Teen Programmers Unite  
 

 

Return to forum top

Need Some Help, plz

Posted by andymcnab [send private reply] at June 07, 2002, 03:17:00 AM

Hello again, sorry to post AGAIN but im trying to work on my sripting language in Visual Basic and i have a prob:
in python you can do this:

>>> word = "HelpA"
>>> word[-1] # The last character
'A'
>>> word[-2] # The last-but-one character
'p'
>>> word[-2:] # The last two characters
'pA'
>>> word[:-2] # All but the last two characters
'Hel'

what im getting at is that in python you can take off letters and stuff at beggining and end but in Visual Basic 6 this doest seem to be able to happen!
Please could you suggest a way in which i could do this??? plz
The reason i need it is because if im doing a scripting language i need it so that if the user types in: (example)
print "Hello"
then it will print just hello hence knocking off the first 7 characters and the last one, thanx (like printf in VC++)

-andymcnab
all help appreciated

Posted by buzgub [send private reply] at June 07, 2002, 03:21:06 AM

look up "mid" in the documentation.

Posted by andymcnab [send private reply] at June 07, 2002, 03:36:10 AM

take a look at this if u wouldnt mind:

Dim start As String
start = "print "
ElseIf Text2.Text = "print " Then
Text1.Text = Mid(start, 6, 200)
Else
Text1.Text = Text1.Text & "Unrecognised command" & vbNewLine

End If
Text2.Text = ""

I need to tell VB that text will come after the "print ", how do i do that plz? Cos i cant exactly predict what the user will input, thanx
p.s your help is graetly appreciated!

-andymcnab

Posted by metamorphic [send private reply] at June 07, 2002, 06:55:14 AM

like i told you before, you use some sort of seperator. I sugested using something like a colon (:) becasue it prob wouldn't be used for anything else. then do this:

assuming the user input box is text1 (what the user types commnds into) and the output box (outputs the relevant data depending on command) is text2 and the button to start the script running is called cmd1 and the seperator is a :

private sub cmd1_click()

dim currentchar as string *1
dim operand as string
dim command as string

for x = 1 to len(text1.text)
  text1.selStart = (x-1)
  text1.selLength = 1
  text1.selText = currentchar
  if currentchar = ":" then
     text1.selStart = 0
     text1.selLength = x - 1
     text1.selText = operand
     text1.selStart = x + 1
     text1.selLength = len(text1.text)
     text1.selText = command
     break
next x



that (in theory) gives you your command and operand, i havnt tested it though becasue i don't have VB here. You can then take those 2 variables and do a select case on the operand.

I could of used left() and right() functions, but i can't remember how to use them.

Try than and see what happens
Posted by andymcnab [send private reply] at June 07, 2002, 07:41:51 AM

okay thanx i will do.

-andymcnab

Posted by metamorphic [send private reply] at June 07, 2002, 08:13:36 AM

andy, if it dosent work and you still want help, just ask. I will be around my dads house later today about 18:00 GMT and i have VB there if you still need some help.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.