Some String Fuctions Broke?

BlitzMax Forums/BlitzMax Programming/Some String Fuctions Broke?

DaY(Posted 2005) [#1]
been trying the new gui stuff and as i was trying to make a simple serial program i noticed that ( ToInt ToLong ToFloat ) String Modyfiers Are Broke Or Have Been Removed But Not Documented So Any One Else Get This.

[Code]
Strict


Local Window:TGadget
Local Button:TGadget[2]
Global TextIn:TGadget[2]
Global Name_string$
Global Name_Length
Global Name_Int

Window = CreateWindow( "CrackMEH",40,40,200,200 )
Button[0] = CreateButton( "Ok",5,80,80,30,Window,BUTTON_OK )
Button[1] = CreateButton( "Exit",105,80,80,30,Window,BUTTON_CANCEL )
TextIn[0] = CreateTextField(20,30,150,20,Window)
TextIn[1] = CreateTextField(20,50,150,20,Window)



SetGadgetText( TextIn[0],"Enter Name" )
SetGadgetText( TextIn[1],"Enter Serial" )


ActivateGadget TextIn[0]
ActivateGadget TextIn[1]


While WaitEvent()
Select EventID()
Case EVENT_GADGETACTION
Select EventSource()


Case TextIn[0]
Get_Text_And_Calc()


Case TextIn[1]


Case Button[0]
SetGadgetText( TextIn[0],Name_Int )


Case Button[1]
End


End Select
Case EVENT_WINDOWCLOSE
End
End Select
Wend

Function Get_Text_And_Calc()
Name_string$ = TextFieldText$( TextIn[0] )
Trim$( Name_string$ )
Name_Length = Len( Name_string$ )
Name_Int = ToInt( Name_string$ )
EndFunction
[/Code]


Leiden(Posted 2005) [#2]
Removing the To before the Int seems to work. When I click OK name just becomes 0, is that desired or does it mean its not working,


JazzieB(Posted 2005) [#3]
It's not broke, you're just using them the wrong way.
Name_Int=ToInt(Name_string$)

Should be
Name_Int=Name_string.ToInt()



Leiden(Posted 2005) [#4]
Ah yeah that works, it was my initial thought but I only remembered ever using ToCString(), I didnt know those commands existed,


DaY(Posted 2005) [#5]
yea that works but it just gives me the number it dont do the desired Convert String To Int That I wanted :/

as i wanted to get the name imput change it to an Int so i can mess about with it to get a serial from the name but it always 0 and one wana show me the correct way of doing this lol as im a newb with blitmax.

i want sommet like
Name = DaY
Int = wotever the int of day is
length of day = 3

so 3xInt = serial

that type of thing.

you will have to excuse my spelling etc but im dyslexic :)


TomToad(Posted 2005) [#6]
You mean something like this?
Local a:string = "123"
Local b:int = Int(a)
Print "String is "+a+". Int is "+b



JazzieB(Posted 2005) [#7]
I don't think you understand what ToInt does. It turns a string that contains a numeric value into it's actual integer value. So a string with "123" in it can be converted into the actual integer value and manipulated just like any other numerical value. Other examples are...

"46" > 46
"01 555 123" > 1
"123abc" > 123
"Mr Smith" > 0

Do you see what it's doing?

As you want to use a player's name to come up with a serial number, then your starting point should be with the ASCII values of each character of the string. You can use Mid() and Asc() to retrieve the ASCII codes, but it's then up to you how you use them to come up with a serial number.


FlameDuck(Posted 2005) [#8]
Or perhaps something like this:
SuperStrict

Local name:String = Input( "Type your name here: " )
Local accum:Int  = 0
For Local n:Int = 0 Until name.length
	accum:+name[n]
Next
Local serial:Int = 3 * accum
Print "Name   : " + name
Print "Int    : " + accum
Print "Serial : " + serial
End
It goes without saying that this is not a particularly good and/or secure way to generate serial numbers.


DaY(Posted 2005) [#9]
aye guess i dont now how to use it lol just ust to doing this with purebasic and i now the serial would suck ;) im just doing it to get to grips with the gui