Value Conversion Error

J

Jake

I am using the following code to retrieve text from a frame

Function GetValue() As Singl

Dim frm As Fram
Dim frmChoice As Fram
Dim intLCV As Intege
Dim strNewString As Strin
Dim varHolder As Varian

For Each frm In Frame
If frm.HorizontalPosition = 138.3 The
frm.Selec
Set frmChoice = fr
End I
Next fr

For intLCV = 1 To Len(frmChoice.Range.Text
If Mid(frmChoice.Range.Text, intLCV, 1) <> "," The
strNewString = strNewString & Mid(frmChoice.Range.Text, intLCV, 1
End I
Next intLC

varHolder = CSng(strNewString

GetValue = varHolde

Set frm = Nothin
Set frmChoice = Nothin

End Functio

The line varHolder = CSng(strNewString) keeps returning an error. The value of strNewString is " 6271.84" (yes, there is a leading space) and I can't for the life of me figure out why there is a problem. I have also tried first setting varHolder to the value of strNewString, then converting to a single to no avail

Any ideas why this isn't working

Thanks

Jake
 
D

Doug Robbins - Word MVP

Hi Jake,

The following does not produce an error:

Dim varHolder As Variant, strNewString As String
strNewString = " 6271.84"
varHolder = CSng(strNewString)
MsgBox varHolder

Try throwing in a few message boxes to ensure that strNewString does contain
what you think it does - " 6271.84"

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Jake said:
I am using the following code to retrieve text from a frame:

Function GetValue() As Single

Dim frm As Frame
Dim frmChoice As Frame
Dim intLCV As Integer
Dim strNewString As String
Dim varHolder As Variant

For Each frm In Frames
If frm.HorizontalPosition = 138.3 Then
frm.Select
Set frmChoice = frm
End If
Next frm

For intLCV = 1 To Len(frmChoice.Range.Text)
If Mid(frmChoice.Range.Text, intLCV, 1) <> "," Then
strNewString = strNewString & Mid(frmChoice.Range.Text, intLCV, 1)
End If
Next intLCV

varHolder = CSng(strNewString)

GetValue = varHolder

Set frm = Nothing
Set frmChoice = Nothing

End Function

The line varHolder = CSng(strNewString) keeps returning an error. The
value of strNewString is " 6271.84" (yes, there is a leading space) and I
can't for the life of me figure out why there is a problem. I have also
tried first setting varHolder to the value of strNewString, then converting
to a single to no avail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top