|
-
Apr 9th, 2005, 12:43 PM
#1
Thread Starter
Lively Member
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:
strB = "----------------------------------------"
txtAmajSpc.Text = intAmajSpc
lngPos = Val(intAmajSpc)
lngPos = lngPos
strFretNumb = "2"
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?!
-
Apr 9th, 2005, 12:52 PM
#2
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:
Private Sub Command1_Click()
Dim lngPos%, strFretNumb$, strB$
strB = "----------------------------------------"
lngPos = 3
strFretNumb = "2"
strB = Left$(strB, lngPos - 1) & strFretNumb & Mid$(strB, lngPos + 1)
Debug.Print strB
End Sub
-
Apr 9th, 2005, 12:57 PM
#3
Thread Starter
Lively Member
Re: Mid$ Function Not Working
I need txtAmajSpc.Text = AmajSpc so that the user can assign a value to the lngPos long.
-
Apr 9th, 2005, 01:22 PM
#4
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.
-
Apr 9th, 2005, 01:25 PM
#5
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)
-
Apr 9th, 2005, 01:26 PM
#6
Thread Starter
Lively Member
Re: Mid$ Function Not Working
[Highlight=VB]
VB Code:
strB = "----------------------------------------"
txtAmajSpc.Text = strAmajSpc
lngPos = Val(strAmajSpc)
strFretNumb = "2"
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)
-
Apr 9th, 2005, 01:53 PM
#7
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)
-
Apr 9th, 2005, 01:59 PM
#8
Thread Starter
Lively Member
Re: Mid$ Function Not Working
You're a genius, did I mention that you are the smartest person alive
Thanks alot.
-
Apr 9th, 2005, 02:07 PM
#9
Thread Starter
Lively Member
Re: Mid$ Function Not Working
Ok that works now. I just need to know how I can combine this:
VB Code:
AStart = strHE & vbCrLf & strB & vbCrLf & strG & vbCrLf & strD & vbCrLf & strA & vbCrLf & strLE
txtWriteTab.Text = AStart
to this:
VB Code:
BStart = strHE & vbCrLf & strB & vbCrLf & strG & vbCrLf & strD & vbCrLf & strA & vbCrLf & strLE
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?
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
|