[Gambas-user] Bug / changed behaviour of Input
Emil Lenngren
emil.lenngren at ...626...
Wed Mar 14 19:32:58 CET 2012
That's the difference, If you pass the string "1234" to Read As Integer,
you get the Integer 875770417, because "1234" is in ascii 49 50 51 52, and
49 + 50*(2^8) + 51*(2^16) + 52*(2^24) = 875770417.
If Input only returns the raw string, the user can do the Val on his/her
own afterwards, if he/she wants to.
In most cases (if Input simply returns the raw string),
Dim a As Integer
Input a
is good, because Input returns a String, and correct string to int
conversion is done automatically.
/Emil
2012/3/14 Jussi Lahtinen <jussi.lahtinen at ...626...>
> > Lol, there is a LOT of usage for scanf :)
> >
>
> Yes, I'm sure it has (it's on stdio).
> I just haven't need it.
>
>
>
> > If we say c++ istream instead, then you have cin >> a >> b >> ...
> > If I want to read a text file word by word, (where a word is something
> > whitespace-separated, space on newline), cin >> is quite easy to use.
> > Gambas Input works about in the same way, but the Val thing can in some
> > cases be strange so you don't know what you really get. There is Line
> Input
> > which always gives a string, but it only separates on newline, not any
> > whitespace.
> >
>
> So, maybe Input should be without Val kind of feature, then it could be
> used to safely parse txt files, etc.
> In my opinion syntax s = Input As String, i = Input As Integer, etc doesn't
> make it useful.
> If you know when there is string and when integer, then you should use Read
> instead.
>
> Maybe Input could have optional argument to switch on/off interpretation of
> read values...
>
> Jussi
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> 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