Valhalla Legends Forums Archive | Visual Basic Programming | Cast from string...? [VB.NET]

AuthorMessageTime
CrAz3D
[code]On Error GoTo ih
                    ML(UBound(ML)).UsernameFROM = Username
                    Form1.GlobalForm.Chat(True, True, System.Drawing.Color.Azure, "usernamefrom added")
                    ML(UBound(ML)).UsernameTO = cMD(0)
                    Form1.GlobalForm.Chat(True, True, System.Drawing.Color.BurlyWood, "usernameto added")
                    ML(UBound(ML)).Message = str.Right(pA(1), Len(pA(1)) - cMD(0))
                    Form1.GlobalForm.Chat(True, True, System.Drawing.Color.CadetBlue, "message added")
                    ML(UBound(ML)).Time = System.DateTime.Now
                    Form1.GlobalForm.Chat(True, True, System.Drawing.Color.DeepPink, "tiem added")
                    ReDim Preserve ML(UBound(ML) + 1)
                    SendW("Mail to " & cMD(0) & " added to delivery list")[/code]

All goes fine through UsernameTO =, after that I recieve the following error:
[quote]Cast from string "craz3d[xl]" to type 'Double' is not valid[/quote]

My original string was:
craz3d[xl] hi there dood
cMD(0) ends up being craz3d[xl]

My Mail Structure is:
[code]    Public Structure MailList
        Public UsernameTO As String
        Public UsernameFROM As String
        Public Message As String
        Public Time As String
    End Structure
    Public ML() As MailList[/code]

Help is appreciated.
October 12, 2004, 12:05 AM
CrAz3D
Oops, problem was a stupid thing.

Forgot to use then length function for cMD(0) when trying to set the message, my bad.
October 12, 2004, 12:41 AM
Myndfyr
Out of curiousity, why are you using "On Error Goto" in VB.NET?  VB.NET uses SEH (Structured Exception Handling), in which you should be using Try...Catch, Try...Finally, or Try...Catch...Finally blocks to handle errors.  Using On Error Goto is bad practice in VB.NET.

Another question: Why are you using a Structure and not a Class?  If you use a structure, references to the strings need to be duplicated, resulting in a reallocation of 16 bytes of memory for each duplication of a structure, whereas when you use a class, you'll only need to duplicate a reference to that class instance, costing only 4 bytes of memory.
October 13, 2004, 2:31 AM
CrAz3D
Thank you, I will look into Try & Finally & Catch and also look at using classes instead of structures.
October 13, 2004, 5:12 AM

Search