Skip to content

XQT 1.3

XQT, the XPath Query Tool, is updated to version 1.3. This version lets you select a node in the tree, and copy it’s path. Also, some bugs are fixed and a few interface inprovements are made. Check the Programs page for download link.

Categories: Programs.

Tags:

The easiest way to get started with Basic

Let’s say that you’re not really a programmer, but perhaps an old Sinclair-user or Commodore user. What is the easiest way to get started with programming on a modern PC?

Install Microsoft Small Basic from here (it’s completely free). Click Download Small Basic, and just follow the instructions. When the installation is complete, you will have a start menu item that looks like this:

Now, things are really easy. A document is a program. Write your code and hit F5 to run it. Here I have written a Hello world program, started it, and the result is this:

Press any key to continue editing.

Context help is always displayed to the right in the main windows of Small Basic, so that you will always know what the code you write actually does. And if you don’t know what to write at all, an easy tutorial can be found here.

Are you looking for a random number generator, try Math.GetRandomNumber. Specify the largest number you want. This code will display 100 numbers between 1 and 10.

For I=1 To 100
  TextWindow.WriteLine(Math.GetRandomNumber(10))
EndFor

Categories: Microsoft .NET.

Tags:

Calling methods on uninitiated variables

If you don’t assign a value to an object variable, it will have the value Nothing (equivalent to null in C#). These two lines of code will therefore effectively do exactly the same thing, even though the second version will produce slightly more assembly:

Dim MyString As String

…and…

Dim MyString As String = Nothing

If you create an extension method on the String class, and you write it in such fashion that it can handle uninitialized variables, it will be able to do so. The extension is done to the type, not to the object. This is an example of a function that checks if a string is empty:

<System.Runtime.CompilerServices.Extension()> _
Public Function IsEmpty(ByVal S As String) As Boolean
   If S Is Nothing Then
      Return True
   Else
      Return (S = "")
   End If
End Function

When the above extension is present, the following piece of code…

Dim MyString As String = Nothing
Console.WriteLine(MyString.IsEmpty())

…displays the word True in your console window!

Categories: Visual Studio 11.

SRT Tool 1.2

SRT Tool is upgraded to version 1.2. You can download it from the Programs page.

Categories: Programs.

Tags:

Reading sequential data from your 5.25 inch floppy

Continued from here.

Once you have some sequential data in a file on your disk, you can write a program to read it back. How this is done, varies between different Commodore machines, and can be quite tricky. On the C128, it is as easy as writing the data. You have to remember the structure of the data you were writing – in my case one string, one integer and one string.

This is a new program (clear any existing program by typing NEW), and it is assumed that you have your floppy with the data you created in the earlier post.

Use OPEN to open a file, but this time, specify that you want to READ the sequential file TEST.DAT.

10 OPEN 1, 8, 2, "TEST.DAT,SEQ,READ"

Then, use INPUT# to read each stored record. Just remember the data types. PRINT# supports writing multiple records in one call, and INPUT# supports multiple reads. So instead of writing three lines, I can read three records in one line, like so:

20 INPUT#1, A$, B, C$

Use CLOSE to close the file.

30 CLOSE 1

These line will display the file content on screen:

40 PRINT A$
50 PRINT B
60 PRINT C$

And if everything is correct, you will now se this:

ONE STRING
 5
ANOTHER STRING

(The commands I use are available Commodore Basic 4.0 on Commodore PET, but I run Commodore Basic 7 on a C128.)

Categories: Geeky.

Sequential data on 5.25 inch floppies

If you have an actual 1571 disk drive for your Commodore 128, insert a blank disk, format it using the HEADER command. Something like this:

HEADER "MY DISK", I44, D0

(Formatting a disk takes a while.)

If you are running a virtual Commodore 128 in VICE, click File, Attach disk image, Drive 8. Create a d64 image file and attach that image. To create the file, enter a desired filename, like test.d64, provide a name, click Create Image, then click Attach.

(The commands I use are available Commodore Basic 4.0 on Commodore PET, but I run Commodore Basic 7 on a C128.)

Your disk is now inserted and completely empty. You can check the content using the DIRECTORY command.

As a Commodore user, you know that you sometimes have to refer to your disk drive using its drive number (the first disk drive is 0) and sometimes you have to use the device number (the first disk drive is 8). The OPEN command operates on any device, therefore a device number is required in this case. The first parameter is the logical file number (just a number that identifies the file), the second is the device number (8). The third argument is a channel number – enter 2. Then, in one single string argument, you type in the file name, the file type and the file mode. I want to create a file called TEST.DAT as a sequential file and I want to write to it, so I my string holds “TEST.DAT,SEQ,WRITE”.

10 OPEN 1, 8, 2, "TEST.DAT,SEQ,WRITE"

To fill your file with data, use the PRINT# command. Anything goes here. This will print one string, one integer, and then yet another string. You provide your logical file number so that PRINT# knows what file you are targeting.

20 PRINT#1, "ONE STRING"
30 PRINT#1, 5
40 PRINT#1, "ANOTHER STRING"

If you like, more data can be added in one line.
When you are done writing, close the file using the CLOSE command. Again, provide your logical file number.

50 CLOSE 1

After running this program, you should have a small sequential file called TEST.DAT on your disk. If any disk error occurred, the lamp on your drive is flashing now – it shouldn’t do that.

Continued here.

Categories: Geeky.

Tags:

Skeptikerforum stänger 2012-06-01

Skeptikerforum, inklusive mediasidan, stängs permanent 2012-06-01. För den som vill debattera eller läsa om det senaste inom skeptikerrörelsen rekommenderas:

Om du har inlägg eller länkar som du vill spara, ska det göras före juni 2012. Fram till 2012 går det bra att posta nya inlägg, såvida du inte registrerat från någon publik e-posttjänst (typ Hotmail eller gMail),

Categories: Skeptical movement.

Reading out SQL Data with named columns

This code reads out names from the Employees table of the Northwind database. You must correct the Data Source property in the connection string for it to run.

#Create a connection object and open it.
[String]$cns="Data Source=XXX;Initial Catalog=Northwind;
   Integrated Security=True"
[System.Data.SqlClient.SqlConnection]$connection=New-Object
   -TypeName System.Data.SqlClient.SqlConnection -ArgumentList $cns
$connection.Open()

#Create a command and execute it.
[String]$query="SELECT FirstName, LastName
   FROM dbo.Employees ORDER BY LastName, FirstName"
[System.Data.SqlClient.SqlCommand]$command=New-Object
   -TypeName System.Data.SqlClient.SqlCommand
$command.Connection=$connection
$command.CommandText=$query
$r=$command.ExecuteReader()

#Iterate the result.
while($r.Read()) {

    #Read out first name.
    [String]$firstname=""
    if( -not $r.IsDBNull(0)) {
        $firstname=$r.GetString(0)
    }

    #Read out last name.
    [String]$lastname=""
    if( -not $r.IsDBNull(1)) {
        $lastname=$r.GetString(1)
    }

    #Display.
    Write-Output ($firstname + " " + $lastname)
}

#Close the reader.
$r.Close()

$connection.Close()
$connection.Dispose()

Here I use column indexes when referring to columns. A change in the SQL query will produce errors in the code that reads out the result. The solution is to call the GetOrdinal function of the reader to get the indexes of the columns, like this:

#Create a connection object and open it.
[String]$cns="Data Source=XXX;Initial Catalog=Northwind;
   Integrated Security=True"
[System.Data.SqlClient.SqlConnection]$connection=New-Object
   -TypeName System.Data.SqlClient.SqlConnection -ArgumentList $cns
$connection.Open()

#Create a command and execute it.
[String]$query="SELECT FirstName, LastName
   FROM dbo.Employees ORDER BY LastName, FirstName"
[System.Data.SqlClient.SqlCommand]$command=New-Object
   -TypeName System.Data.SqlClient.SqlCommand
$command.Connection=$connection
$command.CommandText=$query
$r=$command.ExecuteReader()

#Get use named columns.
[int]$Index_FirstName=$r.GetOrdinal("FirstName")
[int]$Index_LastName=$r.GetOrdinal("LastName")

#Iterate the result.
while($r.Read()) {

    #Read out first name.
    [String]$firstname=""
    if( -not $r.IsDBNull($Index_FirstName)) {
        $firstname=$r.GetString($Index_FirstName)
    }

    #Read out last name.
    [String]$lastname=""
    if( -not $r.IsDBNull($Index_LastName)) {
        $lastname=$r.GetString($Index_LastName)
    }

    #Display.
    Write-Output ($firstname + " " + $lastname)
}

#Close the reader.
$r.Close()

$connection.Close()
$connection.Dispose()

Now, if you change the the query, the reader will still find the desired columns.

Categories: PowerShell.

Five reasons to choose Windows before Mac

5. Design. There are a huge number of computers to choose from. The only constant is change. The few Mac machines on the market are OK, but you can find lots and lots of machines running Windows, including masterpieces Mac users only can dream of.

4. Software. The “killer software” that makes a Mac worth owning (Safari, Cubase, Photoshop, Propellerheads Reason, Firefox) is perfectly available on Windows. Also, for each Mac specific application you can find, there are at least ten Windows specific alternatives.

3. Memory cost. A larger number of vendors and in some cases larger vendors, provides customer value.

2. Ease of use. Windows is well documented, logically constructed. To install an application on Windows, you download it and confirm that you want to install it. You don’t have to know what drag and drop operations that you expect to perform, and therefore, you don’t need any experience to get by. Experience gives you advantages, but is not required.

1. Customisation and extensibility. The smallest edition of the extremely powerful code editor is free to use for any purpose, and just about any Microsoft application comes with a well documented programming interface. And if you want to start from scratch, the .NET Framework is without competition. In both cases, no matter what programming language you know.

Categories: Microsoft .NET.

Vic 20 software

The Vic 20 is not dead yet. I just found this lovely site packed with Vic 20 games and tools. To run a game in the Vice emulator, just download the prg file (download link might be hard to find for some of the programs) and autostart it from the File menu in Vice. Happy hacking in 176 x 184 pixels!

Categories: Geeky.

Tags: