convert string to int

ovt001

Member
Licensed User
Longtime User
Hi boys,
sorry for my stupid question, but I forgot how to convert a string to an integer with b4a.

I made a EditText object but I need to use it to make a Socket connect.
Problem is that the TCP port must be an Int....

thank you
O.
 

ovt001

Member
Licensed User
Longtime User
Dear Erel.

If I use:
Socket1.Connect("10.100.100.103",123,5000)

it work's

but if I use
Socket1.Connect(strServer,intPort,5000)

It doesn't works, but strServer contains "10.100.100.103" and intport contains 123

See code down

Sub btnConnect_Click
Dim intPort As Int = txtPort.Text
Dim strServer As String
strServer = txtServerIp
Socket1.Initialize("Socket1")
Socket1.Connect(strServer,intPort,5000)
'Socket1.Connect("10.100.100.103",123,5000)
end sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
By the way, a notice I have and hopefully I don't have to change thread. While quering an sqlite db, noticed that when requesting an int field, and the filed is null, I get a 0. Don't know if this is how it goes, but surely it would be nice for me to throw an error (so I can do other things with the null result). For now, my workaround is to request a string and check if it is 'null'.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@mc73: In order to avoid unwanted 0 in a SQLite table insert, update or query, I have started storing field type (data type) as TEXT even for numbers instead of INTEGER or REAL, except of course for a PRIMARY KEY. By doing so, you can still validate numbers before inserts and updates and you can insert an empty string without a 0 popping up when you query the data.
Your friend Mahares
 
Upvote 0

ovt001

Member
Licensed User
Longtime User
Dear all,
I found the problem.. very stupid I am :signOops: :sign0013:

B4X:
1. Sub btnConnect_Click
2.     Dim intPort As Int = txtPort.Text
3.     Dim strServer As String
4.     strServer = txtServerIp 
5.     Socket1.Initialize("Socket1")
6.     Socket1.Connect(strServer,intPort,5000)
7.     'Socket1.Connect("10.100.100.103",123,5000) 
8. end sub

but the line 4. must be:

4. strServer = txtServerIp.text

Sorry, And thank you for yours helps
O.
 
Upvote 0