|
-
Aug 24th, 2001, 05:30 AM
#1
Input and proccess
Hi,
I'm inputting commands from a file, one of them is to generate a random number, the input is "RndNum(10,90)", how should I split the digits so I can proccess them later? I've tried sevral ways but they don't always work, and I want my system to be as flawless as possible, what I did is used instr to find ( and , but it doesn't work 100%
Thanks in advance!
-
Aug 24th, 2001, 05:42 AM
#2
PowerPoster
Sorry have no idea what u are trying to do. Can u pls be more specific so that i can try to help. are u trying to generate a random number and get a corresponding value that is 100 minus the original value?
Regards
Stuart
-
Aug 24th, 2001, 05:43 AM
#3
Lively Member
U want to extract the 90 and 10 from the string?
id so,try the IsNumeric function.
-
Aug 24th, 2001, 05:45 AM
#4
Frenzied Member
Hmmm . .
Try this . .
VB Code:
Const sString As String = "RndNum(10,90)"
Dim sExp As String
Dim lFirst As Long
Dim lSecond As Long
Dim lPtr As Long
If Left(sString, 6) = "RndNum" Then
sExp = Mid(sString, 8, Len(sString) - 8)
lPtr = InStr(1, sExp, ",")
lFirst = CLng(Left(sExp, lPtr))
lSecond = CLng(Right(sExp, Len(sExp) - lPtr))
End If
You will probably want to replace the string literals as a constant, and also the literal numbers placeholders as constants too.
Hope this helps
-
Aug 24th, 2001, 05:47 AM
#5
Retired VBF Adm1nistrator
VB Code:
Option Explicit
Private Sub Form_Load()
Dim myCommand As String
myCommand = "RndNum(10,90)"
'pretend we've just loaded the command in from a file into myCommand
'now process it
Dim param() As String
Dim commandName As String
commandName = Left(myCommand, InStr(myCommand, "(") - 1)
param = Split(Replace(Replace(Replace(myCommand, commandName, ""), "(", ""), ")", ""), ",")
MsgBox "Command Name : " & vbTab & commandName & vbCrLf & _
"Parameter 1 : " & vbTab & param(0) & vbCrLf & _
"Parameter 2 : " & vbTab & param(1)
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 24th, 2001, 07:21 AM
#6
-
Aug 24th, 2001, 07:36 AM
#7
1 more thing, can you suggest a way to do this also if I have an input like "this is my visit number rndnum(10,90)" ?
Thanks again
-
Aug 24th, 2001, 07:42 AM
#8
I think I did it (so proud), if you have a better idea please tell me
Code:
sString = Mid(sString, InStr(1, sString, "(", 1) + 1, InStr(1, sString, ")", 1) - InStr(1, sString, "(", 1) - 1)
RndNumbers() = Split(sString, ",")
-
Aug 24th, 2001, 07:46 AM
#9
Retired VBF Adm1nistrator
Here's how I'd do it
VB Code:
Option Explicit
Private Sub Form_Load()
Dim myCommand As String, myMsg As String
myCommand = "Blah blah blah RndNum(10,90) sadjoasidjoiasdja"
If (InStr(myCommand, "RndNum") <> 0) Then
Dim param() As String
Dim commandName As String, tempStr As String
tempStr = Mid(myCommand, InStr(myCommand, "RndNum"), InStr(InStr(myCommand, "RndNum"), myCommand, ")") - InStr(myCommand, "RndNum") + 1)
commandName = Left(tempStr, InStr(tempStr, "(") - 1)
param = Split(Replace(Replace(Replace(tempStr, commandName, ""), "(", ""), ")", ""), ",")
myMsg = "Command Name : " & vbTab & commandName & vbCrLf & _
"Parameter 1 : " & vbTab & param(0) & vbCrLf & _
"Parameter 2 : " & vbTab & param(1)
Else
myMsg = "No command found ..."
End If
MsgBox myMsg
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|