Results 1 to 9 of 9

Thread: Input and proccess

  1. #1
    rsitogp
    Guest

    Question 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!

  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3
    Lively Member
    Join Date
    Apr 2001
    Location
    The Netherlands
    Posts
    112
    U want to extract the 90 and 10 from the string?

    id so,try the IsNumeric function.

  4. #4
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253

    Hmmm . .

    Try this . .

    VB Code:
    1. Const sString As String = "RndNum(10,90)"
    2.     Dim sExp As String
    3.     Dim lFirst As Long
    4.     Dim lSecond As Long
    5.     Dim lPtr As Long
    6.    
    7.     If Left(sString, 6) = "RndNum" Then
    8.         sExp = Mid(sString, 8, Len(sString) - 8)
    9.        
    10.         lPtr = InStr(1, sExp, ",")
    11.        
    12.         lFirst = CLng(Left(sExp, lPtr))
    13.         lSecond = CLng(Right(sExp, Len(sExp) - lPtr))
    14.        
    15.     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


  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim myCommand As String
    5.     myCommand = "RndNum(10,90)"
    6.     'pretend we've just loaded the command in from a file into myCommand
    7.    
    8.    
    9.     'now process it
    10.     Dim param() As String
    11.     Dim commandName As String
    12.     commandName = Left(myCommand, InStr(myCommand, "(") - 1)
    13.     param = Split(Replace(Replace(Replace(myCommand, commandName, ""), "(", ""), ")", ""), ",")
    14.    
    15.     MsgBox "Command Name : " & vbTab & commandName & vbCrLf & _
    16.             "Parameter 1 : " & vbTab & param(0) & vbCrLf & _
    17.             "Parameter 2 : " & vbTab & param(1)
    18.    
    19.    
    20. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    rsitogp
    Guest
    Thank you everyone!

  7. #7
    rsitogp
    Guest
    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

  8. #8
    rsitogp
    Guest
    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, ",")

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Here's how I'd do it

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim myCommand As String, myMsg As String
    5.     myCommand = "Blah blah blah RndNum(10,90) sadjoasidjoiasdja"
    6.    
    7.     If (InStr(myCommand, "RndNum") <> 0) Then
    8.        
    9.         Dim param() As String
    10.         Dim commandName As String, tempStr As String
    11.         tempStr = Mid(myCommand, InStr(myCommand, "RndNum"), InStr(InStr(myCommand, "RndNum"), myCommand, ")") - InStr(myCommand, "RndNum") + 1)
    12.         commandName = Left(tempStr, InStr(tempStr, "(") - 1)
    13.         param = Split(Replace(Replace(Replace(tempStr, commandName, ""), "(", ""), ")", ""), ",")
    14.        
    15.         myMsg = "Command Name : " & vbTab & commandName & vbCrLf & _
    16.                 "Parameter 1 : " & vbTab & param(0) & vbCrLf & _
    17.                 "Parameter 2 : " & vbTab & param(1)
    18.                
    19.     Else
    20.    
    21.         myMsg = "No command found ..."
    22.        
    23.     End If
    24.    
    25.     MsgBox myMsg
    26.    
    27. 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
  •  



Click Here to Expand Forum to Full Width