Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
For Each item As Object In ListBox1.Items
            Dim i As Integer = ListBox1.Items.Count - 1
            Try
                With SerialPort1
                    .Write("AT" & vbCrLf)
                    Threading.Thread.Sleep(1000)
                    .Write("AT+CMGF=1" & vbCrLf)
                    Threading.Thread.Sleep(1000)
                    .Write("AT+CMGS=" & Chr(34) & item & Chr(34) & vbCrLf)
                    Threading.Thread.Sleep(1000)
                    .Write(tx1.Text & Chr(26))
                    MsgBox("Sending Message")
                    Exit For
                End With

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

        Next



What did i miss in this code?i tried everything i know but nothing works
Posted
Updated 1-Aug-14 16:40pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Aug-14 22:43pm    
Such questions make little to no sense if you don't explain your goal, what you are trying to achieve with this very fragment of code, what did you expect to get and what you observed instead, why do you feel the results you observed were wrong, and other relevant information.
—SA

1 solution

Please see my comment to the question. This is not a valid question; the only reason for me to place an answer is that I remember your previous question. I still don't know what was your failure or problem, so I'll only discuss some apparent problems.

Let's see:

The line Dim i As Integer = ListBox1.Items.Count - 1 is never used. It is the line remained from your previous code sample from your previous question; at that time, it also did not make any sense at all. Finally, remove it. And, come on: you should understand every single line you write, otherwise your whole work makes no sense. You should write code, not using trial-and-error approach.

As you asked before, you needed, to send the content of the list box items to the serial port. I have no idea what are in your items, but let me assume that you simply want to send the text shown in each item. In this case, use item.ToString. It can be assumed, but what you do is not conceptually correct; the type of the item is System.Object, so it can contain any data. In other cases, you should type-cast item type to its real runtime type (do you know what is that?) and get whatever data it carries.

Don't use multiple string/character concatenation ('&'). Strings are immutable. Do I even have to explain the consequences? Anyway, use string.Format instead:
http://msdn.microsoft.com/en-us/library/system.string.format%28v=vs.110%29.aspx[^].

The above problems tells use that you have little idea on how to write code, but are not immediate reasons of possible failure (which you, again, did not bother to explain).

I cannot see how the serial port was initialized. And it could be initialized with wrong parameters: parity, baud rate, handshake and the like. Please see: http://msdn.microsoft.com/en-us/library/system.io.ports.serialport%28v=vs.110%29.aspx[^].

It majorly depends on the requirements of the device on the other end of your RS-232 cable. By "AT", I can guess it's some modem. You also did not bother to explain what it requires. Check it by yourself according to the device documentation.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900