[Gambas-user] Convert string to integer
Caveat
Gambas at ...1950...
Mon Jan 27 19:28:47 CET 2014
You can't use CInteger on a String that does not represent an Integer!
Either make sure your String is always a 'pure' integer... so "14160" in
place of "14160.0"
Or code qrg_i = Int(CFloat(qrg)), which is much more forgiving.
The reason you get an error is that you make the same mistake twice...
first you ask Gambas to convert the invalid String, then you catch an
error on that statement, but then you again ask Gambas to convert the
invalid String you just got an error on!
Kind regards,
Caveat
On 27/01/14 18:11, Dirk wrote:
> Hi,
>
> I'm having a problem with Convert string to integer
>
>
>
>
> Public Sub MySock_Read() ' Data via Telnet
> ' When some data arrives from the remote
> ' part of the socket, "DataAvailable" event
> ' is raised
> '****************************************
>
> Dim qrg_i As Integer
> Dim qrg As String
> Dim rx, rx2, rxtmp As String
>
> If MySock.Status = Net.Connected Then
> Read #MySock, rx, Lof(MySock)
> rx2 = rx
>
> If Mid$(rx, 1, 5) = "DX de" Then
>
> dxde = Mid$(rx, 1, 5)
> rx = Trim(Replace$(rx, "DX de ", ""))
> i = InStr(rx, " ")
> txcall = Mid$(rx, 1, i)
> rx = Trim(Replace$(rx, txcall & " ", ""))
> qrg = Mid$(rx, 1, InStr(rx, " "))
> rx = Trim(Replace$(rx, qrg & " ", ""))
> dxcall = Mid$(rx, 1, InStr(rx, " "))
> rx = Trim(Replace$(rx, dxcall & " ", ""))
> ' . . . . . . . . . .
>
> qrg = Trim(qrg)
>
> Print "qrg=" & qrg & "<<<" ' out = qrg=14160.0<<<
>
> Try qrg_i = CInteger(qrg)
> If Error Then Error Subst("&1 won't convert", qrg)
> qrg_i = CInteger(qrg) ' <<<== Here is Error
>
> ---
> Dirk
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> CenturyLink Cloud: The Leader in Enterprise Cloud Services.
> Learn Why More Businesses Are Choosing CenturyLink Cloud For
> Critical Workloads, Development Environments & Everything In Between.
> Get a Quote or Start a Free Trial Today.
> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list