Results 1 to 9 of 9

Thread: Mid$ Function Not Working

  1. #1

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Question Mid$ Function Not Working

    Can someone tell me what is wrong with this code. When I try to run it there is a run time error 5 "invalid call, function"...

    VB Code:
    1. strB = "----------------------------------------"
    2.  
    3. txtAmajSpc.Text = intAmajSpc
    4.         lngPos = Val(intAmajSpc)
    5.         lngPos = lngPos
    6.         strFretNumb = "2"
    7.         strB = Left$(strB, lngPos - 1) & strFretNumb & Mid$(strB, lngPos + 1)

    txtAmajSpc is a textbox on form where user inputs a number

    Anyone know what's wrong?!
    Nick

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Mid$ Function Not Working

    What is intAmajSpc and how do you assign value to it?
    Why do you need this: txtAmajSpc.Text = intAmajSpc ???
    Since dfj appears to be an integer then you don't have to use Val() to get its value: lngPos = intAmajSpc
    After all the following is all you need (or similar):
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim lngPos%, strFretNumb$, strB$
    3.    
    4.     strB = "----------------------------------------"
    5.  
    6.     lngPos = 3
    7.     strFretNumb = "2"
    8.     strB = Left$(strB, lngPos - 1) & strFretNumb & Mid$(strB, lngPos + 1)
    9.     Debug.Print strB
    10.  
    11. End Sub

  3. #3

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Mid$ Function Not Working

    I need txtAmajSpc.Text = AmajSpc so that the user can assign a value to the lngPos long.
    Nick

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Mid$ Function Not Working

    Well you sure don't need lngPos = lngPos, but what is the value of lngPos? Put a breakpoint on the strB = Left$(strB, lngPos - 1) & strFretNumb & Mid$(strB, lngPos + 1) line and see what the values are.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Mid$ Function Not Working

    If the user has already filled the TEXT BOX, then that first assignment is backwards.

    Code:
    strB = "----------------------------------------"
    
            intAmajSpc = Va(txtAmajSpc.Text) ' This is probably more what you want
            lngPos = Val(intAmajSpc)
            lngPos = lngPos ' This is not needed
            strFretNumb = "2"
            strB = Left$(strB, lngPos - 1) & strFretNumb & Mid$(strB, lngPos + 1)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Mid$ Function Not Working

    [Highlight=VB]
    VB Code:
    1. strB = "----------------------------------------"
    2.  
    3. txtAmajSpc.Text = strAmajSpc
    4.         lngPos = Val(strAmajSpc)
    5.         strFretNumb = "2"
    6.         strB = Left$(strB, lngPos - 1) & strFretNumb & Mid$(strB, lngPos + 1)

    My string strAmajSpc has a value of zero. In the form I have a text box (txtAmajSpc) that the user can input a number in. Why does it set the value to zero when I click the command push button (code)
    Nick

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Mid$ Function Not Working

    If this line of code is in the command button click event...

    Code:
    txtAmajSpc.Text = strAmajSpc
    And if you said strAmajSpc has a 0 in it...

    Then why would you not expect that line of code to move the 0 into the TEXTBOX?

    These two lines of code will that the value of the TEXT BOX - put it in the string first, and then assign it to the longword variable.

    Code:
            strAmajSpc = txtAmajSpc.Text
            lngPos = Val(strAmajSpc)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Mid$ Function Not Working

    You're a genius, did I mention that you are the smartest person alive

    Thanks alot.
    Nick

  9. #9

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Mid$ Function Not Working

    Ok that works now. I just need to know how I can combine this:

    VB Code:
    1. AStart = strHE & vbCrLf & strB & vbCrLf & strG & vbCrLf & strD & vbCrLf & strA & vbCrLf & strLE
    2.         txtWriteTab.Text = AStart

    to this:

    VB Code:
    1. BStart = strHE & vbCrLf & strB & vbCrLf & strG & vbCrLf & strD & vbCrLf & strA & vbCrLf & strLE
    2.         txtWriteTab.Text = BStart

    Only when the "Astart" is in the textbox, or when "Bstart" is in the textbox. Is there an If and Then statement for this?
    Nick

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