Hi All,

In the below code I take a string and split it, then assign it to a "Label" object.
On my computer it works great but when I "Publish web site" I recieve the .NET error messages "Object reference not set to an instance of an object" and "Index was outside the bounds of the array".

Any idea how to fix it? I've tried in so many ways...

Dim GetPhoneString As String = GetStr("abcd")
        If GetPhoneString.Length < 1 Then
            lbl1.Text = "N\A"
            lbl2.Text = "N\A"
            lbl3.Text = "N\A"
            lbl4.Text = "N\A"
        Else
            Dim MapPhoneData As String() = Split(GetPhoneString, ",")
            lbl1.Text = MapPhoneData(0)
            lbl2.Text = MapPhoneData(1)
            lbl3.Text = MapPhoneData(2)
            lbl4.Text = MapPhoneData(3)
        End If

Recommended Answers

All 11 Replies

can u tell me in GetPhoneString abcd is there & how u r spliting it with , there is no , in string,then how can u do it,& what is Getstr- is it a function?

can u tell me in GetPhoneString abcd is there & how u r spliting it with , there is no , in string,then how can u do it,& what is Getstr- is it a function?

I agree with sonia said ... but I might have phrased it a little better. The underlying code in these methods that weren't posted will help solve this thread.

Yes, basically the GetStr is a function which generate a string like:

1,34,579,77356


Then I split it and assign it to labels:

1
34
579
77356


**Should be very simple...

It was so simple dear.Check it below-

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Getstr As String = "1,34,579,77356"
        Dim sArr() As String
        Dim lCount As Integer
        sArr = Split(Getstr, ",")

        For lCount = 0 To UBound(sArr)
            MsgBox(sArr(lCount).ToString)
            Application.DoEvents()
        Next
    End Sub
End Class

Thanks Sonia.. couple of questions:

1. I need to assign it to four lables, you just send it to MsgBox which is one single string... I don't need it like that.

2. I getting an error when trying to use "Application.DoEvents".
the error: "...is not mamber of HttpApplicationState".

Can you help please?

U can remove application.doevents its not necessary......Can u plz tell me....is this d fixed string or not...Means string can also 1,2,3,4,5,6 & now u assign it to six labels Rite?????/

Yes... string can be 1,2,3 or 33,567,89 or aa,bb,4 and so on...

No No i m asking everytime string could be 1,2,3 means two commas are there in string, If so u can manually put the values in Labels.

Label1.text = 1
label2.text = 2
Label3.text = 3

I have four labels which is three commas..
Now, how to put the values? can you paste an example please?

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim Getstr As String = "1,34,579,77356"
        Dim sArr() As String
        Dim lCount As Integer
        sArr = Split(Getstr, ",")

        For lCount = 0 To UBound(sArr)
            Select Case lCount
                Case 0
                    Label1.Text = sArr(lCount)
                Case 1
                    Label2.Text = sArr(lCount)
                Case 2
                    Label3.Text = sArr(lCount)
                Case 3
                    Label4.Text = sArr(lCount)
            End Select
            Application.DoEvents()
        Next

    End Sub

tell me one thing is dat fixed na, dat element present at postion 0 goes to suppose Label1, element present as position 1 goes to Label2 & so on....Cz i hv do dat way...

Sonia -

Thank you so much for your help!
This is what I was looking for... works great.

Thanks!
ypdev

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.