[Gambas-user] Questions about source code
Michael Stibane
stibs at ...6...
Tue Jul 16 20:30:42 CEST 2002
Hi list!
I tried to comment the console example. I'm no programmer ... better a
preNewbie, please help me out with the questions and false
interpretations between the lines of code for my understanding.
If I see this I could imagine to have a database component for mysql -
simply accessing it via commandline like the bash in this case.
STIBS
-------------------------------
' Gambas class file
PRIVATE §hProcess AS Process
' defines the process identificator variable format
STATIC PUBLIC SUB Main()
' Main routine declaration
DIM hForm AS Form
hForm = NEW FConsole
hForm.Show
' shows the form
END
PUBLIC SUB _new()
' on opening the form happens the following
EXEC "bash --noediting -i" FOR READ WRITE AS §hProcess
' executes the bash for rw as our process
txtCommand.SetFocus
' sets the focus to the text input line
END
PUBLIC SUB Form_Close()
' on hitting the close button x
§hProcess.Kill
' the process will be killed
END
PUBLIC SUB Form_Resize()
' Some screen geometry declarations when the window gets resized
txtCommand.Move(0, ME.ClientH - txtCommand.H, ME.ClientW, txtCommand.H)
' the ME.X inherits from the forms geometry
txtConsole.Move(0, 0, ME.ClientW, txtCommand.Y)
END
PUBLIC SUB Process_Write(sStr AS String)
' getting the string sent to the process also in the TextArea displayed
txtConsole.Pos = txtConsole.Length
' positions the cursor at the end of the TextArea.Text
txtConsole.Insert(Normalize(sStr))
' Inserting the normalized command into the TextArea Output
END
PUBLIC SUB Process_Error(sStr AS String)
' getting the error message from process displayed
txtConsole.Pos = txtConsole.Length
' positions the cursor at the end of the TextArea.Text
txtConsole.Insert(Normalize(sStr))
' Inserting the normalized Error String into the TextArea Output
END
PUBLIC SUB Process_Kill()
' No clue if this is needed because it's Form_Close() is already definded
'§hProcess = NULL
TRY ME.Close
' this is maybe additional when the process dies that the form also dies
END
PUBLIC SUB txtCommand_Activate()
' So Activate is when Enter is hit? :o)
DIM sLig AS String
' defining variable type
sLig = txtCommand.Text & gb.NewLine
' The Text written in the textfield plus a new line is submitted to sLig
txtConsole.Insert(sLig)
' Hmmm? did I understand Process_Write in the wrong way?
txtCommand.Clear
' cleaning
§hProcess.Send(sLig)
' Sending the input to the process
END
STATIC PRIVATE FUNCTION Normalize(sStr AS String) AS String
' that's the next point I don't understand fully
' Does the process just understand ASCII numbers?
DIM sNorm AS String
' normalized String
DIM iInd AS Integer
' index # of the characters position in the string
DIM iCar AS Integer
' needed for the logic
DIM bEsc AS Boolean
' needed for the logic
FOR iInd = 1 TO Len(sStr)
' for all character in the strings (input or output)
iCar = Asc(sStr, iInd)
' get the ASCII numbers
IF iCar = 27 THEN
bEsc = TRUE
CONTINUE
ENDIF
IF bEsc THEN
IF iCar < 32 THEN bEsc = FALSE
CONTINUE
ENDIF
' Some logic about the character format
' Where can I read about this?
' Somewhere has to be an ASCII table with numbers where I also find keys
like <- or ->
' help me out please!
IF iCar < 32 AND iCar <> 10 THEN iCar = 32
' additional logic
sNorm = sNorm & Chr$(iCar)
' the normalized text
NEXT
RETURN sNorm
' returns the normalized string to the program ... but where is it used?
' I don't see sNorm somewhere else ... am I blind?
END
Thanx alot!
--
Best!
STIBS
freehosting at ...7...
More information about the User
mailing list