Example 5 - using console

<< Click to Display Table of Contents >>

Navigation:  Introducing ThinBASIC >

Example 5 - using console

 

Some console usage. Command line parameters reporting.

 

'----------------------------------------------------------------------

 

Uses "console", "os"

 

'---Returns the number of commands specified in command line

Long NumberOfCommands = OS_GetCommands

 

'---Some header

Console_WriteLine("The following are the passed parameters:")

Console_WriteLine(Repeat$(79, "-"))

 

'---Show all parameters

'---See OS_GetCommand function

Long Count

For Count = 0 To NumberOfCommands

Console_WriteLine( Format$(Count, "00") & " " & OS_GetCommand(Count))

Next

 

'---If only 1 param then exit

'---Only 1 parameter means no parameters because parameter 1 is always script name.

If NumberOfCommands <= 1 Then

Console_WriteLine( "Only 1 parameter, program stopped. Press a key to Continue")

Console_WaitKey

Stop

End If

 

'---If more than 1 param, make some tests just for example ...

For Count = 1 To NumberOfCommands

Select Case Ucase$(OS_GetCommand(Count))

  Case "COMPUTERNAME"

    Console_WriteLine(OS_GetCommand(Count) & ": " & OS_GetComputerName)

 

  Case "USERNAME"

    Console_WriteLine(OS_GetCommand(Count) & ": " & OS_GetUserName)

 

  Case Else

    Console_WriteLine("Unknown command: " & SelectExpression)

 

End Select

Next

 

Console_WriteLine("Press a key to continue...")

Console_WaitKey