Page 1 of 2

Decimal vs Comma will this work

Posted: Fri Jan 09, 2015 6:50 am
by VB6_to_PBx
Decimal vs Comma will this work like IsNumeric ??

try inputing Values like
4.563 with decimal like for USA Keyboard
and
4,563 with comma for France or Germany or other Countries

does this Code work OK with User's Country Keyboard Settings
as far as if Decimal or Comma ??

need someone to test this Code with France or Germany or other Countries
to see if it works correctly ??

Code: Select all

;        Decimal_VS_Comma__test.pb

Declare InputMAX()
Declare ClearCalc()
Declare Calc()

Global Var1.d , Var2.d , Txt.s
Var1 = 0 : Var2 = 0

Define.i Event

Txt = #CRLF$ + #CRLF$ + "Enter a value between" + #CRLF$ + "1.0000 to 7.0000"

Enumeration 
    #Window_0
    #Menu_0
    #Verdana9
    #Verdana10
EndEnumeration

LoadFont(#Verdana9,"Verdana", 9)
LoadFont(#Verdana10,"Verdana", 10)

;-----< GUI section >-----
Procedure OpenWindow_0(x = 0, y = 0, width = 300, height = 250)

    OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |
                                                   #PB_Window_SizeGadget | #PB_Window_ScreenCentered )
         SetWindowColor(#Window_0,RGB(240,240,240))

    StringGadget(1, 5, 20, 70, 22, "",#PB_Text_Center) : SetGadgetFont(1, FontID(#Verdana9)) : SetGadgetAttribute(1,#PB_String_MaximumLength,7)
    StringGadget(2, 100, 20, 70, 22, "",#PB_Text_Center) : SetGadgetFont(2, FontID(#Verdana9)) : SetGadgetAttribute(2,#PB_String_MaximumLength,7)
    StringGadget(3, 5, 45, 165, 22, "",#PB_Text_Center) : SetGadgetFont(3, FontID(#Verdana9)) : SetGadgetColor(3,#PB_Gadget_BackColor,RGB(250,250,0))
    ButtonGadget(4, 5, 70, 165, 38, "Calculate") : SetGadgetFont(4, FontID(#Verdana10))

    TextGadget(5,80,20,9,22,"X") : SetGadgetFont(5, FontID(#Verdana10))
    TextGadget(6,5,120,280,100,"",#PB_Text_Center | #PB_Text_Border) : SetGadgetFont(6, FontID(#Verdana10)) : SetGadgetColor(6, #PB_Gadget_BackColor,RGB(255,255,255))

EndProcedure


OpenWindow_0()

AddKeyboardShortcut(0, #PB_Shortcut_Return, 13)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 27)

SetActiveGadget(1) : SendMessage_(GadgetID(GetActiveGadget()), #EM_SETSEL, 0, -1)

;-----< Input Section >-----
Repeat
    Event = WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow
         Select EventWindow()
         Case 0 : CloseWindow(0) : End
         EndSelect
    Case #PB_Event_Gadget
         Select EventGadget()
         ;-----< StringGadgets >-----
         Case 1  ; Var1
              Select EventType()
              Case #PB_EventType_Focus 
                   SetGadgetText(6,"Input Variable 1" + Txt)
                   SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
              Case #PB_EventType_Change
                   Var1 = ValD(GetGadgetText(1)) : ClearCalc()
                   If Var1 > 7 : InputMAX() : SetGadgetText(1,"") : SetActiveGadget(1) : EndIf
              Case #PB_EventType_LostFocus
                   If Var1 >= 1 And Var1 <= 7 : SetGadgetText(1,StrD(Var1,4)) : Else : SetGadgetText(1,"") : EndIf
              EndSelect
         Case 2  ; Var2
              Select EventType()
              Case #PB_EventType_Focus 
                   SetGadgetText(6,"Input Variable 2" + Txt)
                   SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
              Case #PB_EventType_Change
                   Var2 = ValD(GetGadgetText(2)) : ClearCalc()
                   If Var2 > 7 : InputMAX() : SetGadgetText(2,"") : SetActiveGadget(2) : EndIf
              Case #PB_EventType_LostFocus 
                   If Var2 >= 1 And Var2 <= 7 : SetGadgetText(2,StrD(Var2,4)) : Else : SetGadgetText(2,""): EndIf
              EndSelect
         Case 3  ; Yellow Answer Box
         Case 4  ; Calc() Button
              Select EventType()
              Case #PB_EventType_Focus
              Case #PB_EventType_LeftClick : Calc()
              Case #PB_EventType_LostFocus
              EndSelect
         EndSelect

    ;-----< Menus and KeyDown >-----
    Case #PB_Event_Menu
         Select EventMenu()
         Case #PB_Shortcut_Return
              Select GetActiveGadget()
              Case 1 : SetActiveGadget(GetActiveGadget() + 1)
              Case 2 : SetActiveGadget(1) 
              EndSelect
         Case #PB_Shortcut_Escape
              Select GetActiveGadget()
              Case 1 : SetActiveGadget(2) 
              Case 2 : SetActiveGadget(GetActiveGadget() - 1)
              EndSelect
         EndSelect
    EndSelect
ForEver

End


Procedure InputMAX()

;   Result = MessageRequester(Title$, Text$ [, Flags])
;   #PB_MessageRequester_Ok          : To have the 'ok' only button (Standard)
;   #PB_MessageRequester_YesNo       : To have 'yes' Or 'no' buttons
;   #PB_MessageRequester_YesNoCancel : To have 'yes', 'no' And 'cancel' buttons

    Title$ = "ERROR  :  Input exceeded Valid Range"
    Text$ = "Input exceeded the maximum allowed value ...." + #CRLF$ + #CRLF$ + "Please enter a Value within the Valid Range"
    MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)

EndProcedure


Procedure ClearCalc()

    SetGadgetText(3,"")

EndProcedure


Procedure Calc()

Protected Cnt.i
For Cnt = 1 To 2
    If Val(GetGadgetText(Cnt)) = 0 : SetActiveGadget(Cnt) : ProcedureReturn : EndIf
    Select GetGadgetText(Cnt)
    Case "","0" : SetActiveGadget(Cnt) : ProcedureReturn
    EndSelect
Next Cnt

Protected Answer.d

Answer = Var1 * Var2

SetGadgetText(3,"Answer = " + StrD(Answer,4))

EndProcedure



Re: Decimal vs Comma will this work

Posted: Fri Jan 09, 2015 12:47 pm
by falsam
VB6_to_PBx wrote:does this Code work OK with User's Country Keyboard Settings
French Keyboard : The answer is no.

Image

It's not important. In France we also use the decimal point :)

Re: Decimal vs Comma will this work

Posted: Fri Jan 09, 2015 2:05 pm
by ts-soft
You use always the decimal point for calculation!
Only to show the value, you can use other separators.

Re: Decimal vs Comma will this work

Posted: Fri Jan 09, 2015 11:52 pm
by VB6_to_PBx
ts-soft wrote:You use always the decimal point for calculation!
Only to show the value, you can use other separators.
French Keyboard : The answer is no.
i was afraid of that .. it would have been too simple !

So
StrD() and Val() are not Locale aware ???

what about when you create a File and Read back that File

is WriteStringN() Locale aware ???

Re: Decimal vs Comma will this work

Posted: Sat Jan 10, 2015 11:19 am
by luciano
I use an easy and dirty trick with:
String$ = ReplaceString(String$, StringToFind$, StringToReplace$ [, Mode [, StartPosition [, NbOccurrences]]])

.....

Var1 = ValD(ReplaceString( GetGadgetText(1),",","."))
replacing "," with "."

Code: Select all

;        Decimal_VS_Comma__test.pb

Declare InputMAX()
Declare ClearCalc()
Declare Calc()

Global Var1.d , Var2.d , Txt.s
Var1 = 0 : Var2 = 0

Define.i Event

Txt = #CRLF$ + #CRLF$ + "Enter a value between" + #CRLF$ + "1.0000 to 7.0000"

Enumeration
    #Window_0
    #Menu_0
    #Verdana9
    #Verdana10
EndEnumeration

LoadFont(#Verdana9,"Verdana", 9)
LoadFont(#Verdana10,"Verdana", 10)

;-----< GUI section >-----
Procedure OpenWindow_0(x = 0, y = 0, width = 300, height = 250)

    OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |
                                                   #PB_Window_SizeGadget | #PB_Window_ScreenCentered )
         SetWindowColor(#Window_0,RGB(240,240,240))

    StringGadget(1, 5, 20, 70, 22, "",#PB_Text_Center) : SetGadgetFont(1, FontID(#Verdana9)) : SetGadgetAttribute(1,#PB_String_MaximumLength,7)
    StringGadget(2, 100, 20, 70, 22, "",#PB_Text_Center) : SetGadgetFont(2, FontID(#Verdana9)) : SetGadgetAttribute(2,#PB_String_MaximumLength,7)
    StringGadget(3, 5, 45, 165, 22, "",#PB_Text_Center) : SetGadgetFont(3, FontID(#Verdana9)) : SetGadgetColor(3,#PB_Gadget_BackColor,RGB(250,250,0))
    ButtonGadget(4, 5, 70, 165, 38, "Calculate") : SetGadgetFont(4, FontID(#Verdana10))

    TextGadget(5,80,20,9,22,"X") : SetGadgetFont(5, FontID(#Verdana10))
    TextGadget(6,5,120,280,100,"",#PB_Text_Center | #PB_Text_Border) : SetGadgetFont(6, FontID(#Verdana10)) : SetGadgetColor(6, #PB_Gadget_BackColor,RGB(255,255,255))

EndProcedure


OpenWindow_0()

AddKeyboardShortcut(0, #PB_Shortcut_Return, 13)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 27)

SetActiveGadget(1) : SendMessage_(GadgetID(GetActiveGadget()), #EM_SETSEL, 0, -1)

;-----< Input Section >-----
Repeat
    Event = WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow
         Select EventWindow()
         Case 0 : CloseWindow(0) : End
         EndSelect
    Case #PB_Event_Gadget
         Select EventGadget()
         ;-----< StringGadgets >-----
         Case 1  ; Var1
              Select EventType()
              Case #PB_EventType_Focus
                   SetGadgetText(6,"Input Variable 1" + Txt)
                   SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
              Case #PB_EventType_Change
                   Var1 = ValD(ReplaceString( GetGadgetText(1),",",".")) : ClearCalc()
                   If Var1 > 7 : InputMAX() : SetGadgetText(1,"") : SetActiveGadget(1) : EndIf
              Case #PB_EventType_LostFocus
                   If Var1 >= 1 And Var1 <= 7 : SetGadgetText(1,StrD(Var1,4)) : Else : SetGadgetText(1,"") : EndIf
              EndSelect
         Case 2  ; Var2
              Select EventType()
              Case #PB_EventType_Focus
                   SetGadgetText(6,"Input Variable 2" + Txt)
                   SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
              Case #PB_EventType_Change
                   Var2 = ValD(ReplaceString( GetGadgetText(2),",",".")) : ClearCalc()
                   If Var2 > 7 : InputMAX() : SetGadgetText(2,"") : SetActiveGadget(2) : EndIf
              Case #PB_EventType_LostFocus
                   If Var2 >= 1 And Var2 <= 7 : SetGadgetText(2,StrD(Var2,4)) : Else : SetGadgetText(2,""): EndIf
              EndSelect
         Case 3  ; Yellow Answer Box
         Case 4  ; Calc() Button
              Select EventType()
              Case #PB_EventType_Focus
              Case #PB_EventType_LeftClick : Calc()
              Case #PB_EventType_LostFocus
              EndSelect
         EndSelect

    ;-----< Menus and KeyDown >-----
    Case #PB_Event_Menu
         Select EventMenu()
         Case #PB_Shortcut_Return
              Select GetActiveGadget()
              Case 1 : SetActiveGadget(GetActiveGadget() + 1)
              Case 2 : SetActiveGadget(1)
              EndSelect
         Case #PB_Shortcut_Escape
              Select GetActiveGadget()
              Case 1 : SetActiveGadget(2)
              Case 2 : SetActiveGadget(GetActiveGadget() - 1)
              EndSelect
         EndSelect
    EndSelect
ForEver

End


Procedure InputMAX()

;   Result = MessageRequester(Title$, Text$ [, Flags])
;   #PB_MessageRequester_Ok          : To have the 'ok' only button (Standard)
;   #PB_MessageRequester_YesNo       : To have 'yes' Or 'no' buttons
;   #PB_MessageRequester_YesNoCancel : To have 'yes', 'no' And 'cancel' buttons

    Title$ = "ERROR  :  Input exceeded Valid Range"
    Text$ = "Input exceeded the maximum allowed value ...." + #CRLF$ + #CRLF$ + "Please enter a Value within the Valid Range"
    MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)

EndProcedure


Procedure ClearCalc()

    SetGadgetText(3,"")

EndProcedure


Procedure Calc()

Protected Cnt.i
For Cnt = 1 To 2
    If Val(GetGadgetText(Cnt)) = 0 : SetActiveGadget(Cnt) : ProcedureReturn : EndIf
    Select GetGadgetText(Cnt)
    Case "","0" : SetActiveGadget(Cnt) : ProcedureReturn
    EndSelect
Next Cnt

Protected Answer.d

Answer = Var1 * Var2

SetGadgetText(3,"Answer = " + StrD(Answer,4))

EndProcedure


Re: Decimal vs Comma will this work

Posted: Sat Jan 10, 2015 11:57 am
by Vera
Hi, I can confirm falsam's result for a german keyboard too.
VB6_to_PBx wrote:what about when you create a File and Read back that File
This is what comes out:

Code: Select all

If CreateFile(0, "valD.txt")
  WriteStringN(0, "3.567,56")
  WriteStringN(0, "3567,56")
  WriteStringN(0, "3567.56")
  CloseFile(0)
EndIf
If ReadFile(0, "valD.txt")
  While Eof(0) = 0
    a$  = ReadString(0)
    Debug "a$ = " + a$
    Debug Val(a$)
    Debug ValD(a$)
    Debug StrD(Val(a$), 4)
    Debug StrD(ValD(a$), 4)
    Debug "--------"
  Wend
  CloseFile(0)
EndIf

; output:

; a$ = 3.567,56
; 3
; 3.566999912261962890625
; 3.0000
; 3.5670
; --------
; a$ = 3567,56
; 3567
; 3567.0
; 3567.0000
; 3567.0000
; --------
; a$ = 3567.56
; 3567
; 3567.56005859375
; 3567.0000
; 3567.5601
; --------

Re: Decimal vs Comma will this work

Posted: Sun Jan 11, 2015 5:49 pm
by VB6_to_PBx
Vera wrote:Hi, I can confirm falsam's result for a german keyboard too.
VB6_to_PBx wrote:what about when you create a File and Read back that File
This is what comes out:

Code: Select all

If CreateFile(0, "valD.txt")
  WriteStringN(0, "3.567,56")
  WriteStringN(0, "3567,56")
  WriteStringN(0, "3567.56")
  CloseFile(0)
EndIf
If ReadFile(0, "valD.txt")
  While Eof(0) = 0
    a$  = ReadString(0)
    Debug "a$ = " + a$
    Debug Val(a$)
    Debug ValD(a$)
    Debug StrD(Val(a$), 4)
    Debug StrD(ValD(a$), 4)
    Debug "--------"
  Wend
  CloseFile(0)
EndIf

; output:

; a$ = 3.567,56
; 3
; 3.566999912261962890625
; 3.0000
; 3.5670
; --------
; a$ = 3567,56
; 3567
; 3567.0
; 3567.0000
; 3567.0000
; --------
; a$ = 3567.56
; 3567
; 3567.56005859375
; 3567.0000
; 3567.5601
; --------
hi Vera ,
thanks for creating + testing "WriteStringN" for me

"WriteStringN" ... should work OK with any Country's Locale Keyboard settings ?
as long as the Input Variable's value gets saved correctly as to Digit Grouping and whether it saves its Comma or Decimal in proper place in String ???



luciano , thanks for that Trick !
luciano
I use an easy and dirty trick with:

String$ = ReplaceString(String$, StringToFind$, StringToReplace$ [, Mode [, StartPosition [, NbOccurrences]]])

.....

Var1 = ValD(ReplaceString( GetGadgetText(1),",","."))

Re: Decimal vs Comma will this work

Posted: Sun Jan 11, 2015 6:26 pm
by Little John
VB6_to_PBx wrote:"WriteStringN" ... should work OK with any Country's Locale Keyboard settings ?
[u]PureBasic docs for WriteStringN()[/u] wrote:Write a string to a file and add an 'end of line' character.
WriteStringN() is not influenced by keyboard settings, nor by any other locale settings.

Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 4:52 am
by VB6_to_PBx
Little John wrote:
VB6_to_PBx wrote:"WriteStringN" ... should work OK with any Country's Locale Keyboard settings ?
[u]PureBasic docs for WriteStringN()[/u] wrote:Write a string to a file and add an 'end of line' character.
WriteStringN() is not influenced by keyboard settings, nor by any other locale settings.
hi Little John ,

i changed up the example Code considerably + adding new things

see if it works OK now ?
i did a quick test using German Keyboard settings ... and it seems to work + save + open file correctly ?

Should work for most Countries Keyboard settings ?

Code: Select all

;        Decimal_VS_Comma__test_v3.pb

EnableExplicit

Declare InputMAX()
Declare CalcClear()
Declare Calc()
Declare CalcHelp()
Declare FileOpen()
Declare FileSave()
Declare ClearAll()

Global Var1.d = 0 , Var2.d = 0 , HelpTxt.s
Define.i Event

Enumeration
    #Window_0
    #Menu_0
EndEnumeration


;-----< Fonts >----- 
Enumeration Fonts
    #Verdana9
    #Verdana9B
    #Verdana10
    #Verdana10B
    #Verdana10BH
    #CourierNew10
    #CourierNew10B
EndEnumeration
;   Regular = #Verdana9   Italic = #Verdana9I   Bold = #Verdana9B   Bold+Italic = #Verdana9BI   H = #PB_Font_HighQuality
;   #PB_Font_Bold       : The font will be bold
;   #PB_Font_Italic     : The font will be italic
;   #PB_Font_Underline  : The font will be underlined (Windows only)
;   #PB_Font_StrikeOut  : The font will be strikeout (Windows only)
;   #PB_Font_HighQuality: The font will be in high-quality mode (slower) (Windows only)
LoadFont(#Verdana9,"Verdana", 9)
;LoadFont(#Verdana9B,"Verdana", 9,#PB_Font_Bold)
LoadFont(#Verdana10,"Verdana", 10)
;LoadFont(#Verdana10B,"Verdana", 10,#PB_Font_Bold)
;LoadFont(#Verdana10BH,"Verdana", 10,#PB_Font_Bold | #PB_Font_HighQuality)
;LoadFont(#CourierNew10,"Courier New", 10)
;LoadFont(#CourierNew10B,"Courier New", 10,#PB_Font_Bold)


;-----< GUI section >-----
Procedure OpenWindow_0(x = 0, y = 0, width = 300, height = 250)

    OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |
                                                   #PB_Window_SizeGadget | #PB_Window_ScreenCentered )
         SetWindowColor(#Window_0,RGB(240,240,240))

    CreateMenu(#Menu_0, WindowID(#Window_0))
         MenuTitle("Files")
              MenuItem(101, "Open")
              MenuItem(102, "Save")
                   MenuBar()
              MenuItem(103, "New File ... clear everything")

    StringGadget(1, 5, 20, 70, 22, "",#PB_Text_Center) : SetGadgetFont(1, FontID(#Verdana9)) : SetGadgetAttribute(1,#PB_String_MaximumLength,7)
    StringGadget(2, 100, 20, 70, 22, "",#PB_Text_Center) : SetGadgetFont(2, FontID(#Verdana9)) : SetGadgetAttribute(2,#PB_String_MaximumLength,7)
    StringGadget(3, 5, 45, 165, 22, "",#PB_Text_Center | #PB_String_ReadOnly) : SetGadgetFont(3, FontID(#Verdana9)) : SetGadgetColor(3,#PB_Gadget_BackColor,RGB(250,250,0))
    ButtonGadget(4, 5, 70, 165, 38, "Calculate") : SetGadgetFont(4, FontID(#Verdana10))

    TextGadget(5,80,20,9,22,"X") : SetGadgetFont(5, FontID(#Verdana10))
    TextGadget(6,5,120,280,100,"",#PB_Text_Center | #PB_Text_Border) : SetGadgetFont(6, FontID(#Verdana10)) : SetGadgetColor(6, #PB_Gadget_BackColor,RGB(255,255,255))

EndProcedure


OpenWindow_0()

AddKeyboardShortcut(0, #PB_Shortcut_Return, 13)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 27)

SetActiveGadget(1) : SendMessage_(GadgetID(GetActiveGadget()), #EM_SETSEL, 0, -1)

;-----< Input Section >-----
Repeat
    Event = WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow
         Select EventWindow()
         Case 0 : CloseWindow(0) : End
         EndSelect
    Case #PB_Event_Gadget
         Select EventGadget()
         ;-----< StringGadgets >-----
         Case 1  ; Var1
              Select EventType()
              Case #PB_EventType_Focus
                   CalcHelp() : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
              Case #PB_EventType_Change
                   Var1 = ValD(GetGadgetText(1)) : CalcClear()
                   ;Var1 = ValD(ReplaceString( GetGadgetText(1),",",".")) : CalcClear()
                   If Var1 > 7 : InputMAX() : SetGadgetText(1,"") : SetActiveGadget(1) : EndIf
              Case #PB_EventType_LostFocus
                   If Var1 >= 1 And Var1 <= 7 : SetGadgetText(1,StrD(Var1,4)) : Else : SetGadgetText(1,"") : EndIf
              EndSelect
         Case 2  ; Var2
              Select EventType()
              Case #PB_EventType_Focus
                   CalcHelp() : SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
              Case #PB_EventType_Change
                   Var2 = ValD(GetGadgetText(2)) : CalcClear()
                   ;Var2 = ValD(ReplaceString( GetGadgetText(2),",",".")) : CalcClear()
                   If Var2 > 7 : InputMAX() : SetGadgetText(2,"") : SetActiveGadget(2) : EndIf
              Case #PB_EventType_LostFocus
                   If Var2 >= 1 And Var2 <= 7 : SetGadgetText(2,StrD(Var2,4)) : Else : SetGadgetText(2,""): EndIf
              EndSelect
         Case 3  ; Yellow Answer Box  ( #PB_String_ReadOnly )
         Case 4  ; Calc() Button
              Select EventType()
              Case #PB_EventType_Focus
              Case #PB_EventType_LeftClick : Calc()
              Case #PB_EventType_LostFocus
              EndSelect
         EndSelect

    ;-----< Menus and KeyDown >-----
    Case #PB_Event_Menu
         Select EventMenu()
         Case 101 : FileOpen()
         Case 102 : FileSave()
         Case 103 : ClearAll()
  
         Case #PB_Shortcut_Return
              Select GetActiveGadget()
              Case 1 : SetActiveGadget(GetActiveGadget() + 1)
              Case 2 : SetActiveGadget(1)
              EndSelect
         Case #PB_Shortcut_Escape
              Select GetActiveGadget()
              Case 1 : SetActiveGadget(2)
              Case 2 : SetActiveGadget(GetActiveGadget() - 1)
              EndSelect
         EndSelect
    EndSelect
ForEver

End


Procedure InputMAX()

;   Result = MessageRequester(Title$, Text$ [, Flags])
;   #PB_MessageRequester_Ok          : To have the 'ok' only button (Standard)
;   #PB_MessageRequester_YesNo       : To have 'yes' Or 'no' buttons
;   #PB_MessageRequester_YesNoCancel : To have 'yes', 'no' And 'cancel' buttons

    Protected Title$ , Text$
    Title$ = "ERROR  :  Input exceeded Valid Range"
    Text$ = "Input exceeded the maximum allowed value ...." + #CRLF$ + #CRLF$ + "Please enter a Value within the Valid Range"
    MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)

EndProcedure


Procedure CalcClear()

    SetGadgetText(3,"")

EndProcedure


Procedure Calc()

    Protected Cnt.i
    For Cnt = 1 To 2
         If Val(GetGadgetText(Cnt)) = 0 : SetActiveGadget(Cnt) : ProcedureReturn : EndIf
         Select GetGadgetText(Cnt)
         Case "","0" : SetActiveGadget(Cnt) : ProcedureReturn
         EndSelect
    Next Cnt

    Protected Answer.d
    Answer = Var1 * Var2

    SetGadgetText(3,"Answer = " + StrD(Answer,4))
    SetActiveGadget(1)

EndProcedure


Procedure CalcHelp()

    Protected Txt.s = #CRLF$ + #CRLF$ + "Enter a value between" + #CRLF$ + "1.0000 to 7.0000" + #CRLF$ + "1,0000 to 7,0000"
    Protected HelpTxt.s

    Select EventGadget()
    Case 1 : HelpTxt = "Input Variable 1" + Txt
    Case 2 : HelpTxt = "Input Variable 2" + Txt
    EndSelect
    
    SetGadgetText(6,HelpTxt)

EndProcedure


Procedure FileOpen()

    Protected Cnt.i

    If ReadFile(0, "C:\PureBASIC\_____New___Source_Codes\valD.txt")       ;<--- change File Location and Name to your needs

         ClearAll()

         While Eof(0) = 0
              SetGadgetText(1,ReadString(0, #PB_Ascii)) : Var1 = ValD(GetGadgetText(1))
              SetGadgetText(2,ReadString(0, #PB_Ascii)) : Var2 = ValD(GetGadgetText(2))
         Wend

         CloseFile(0)

         SetWindowTitle(#Window_0,"FileName :  valD.txt")

         For Cnt = 2 To 1 Step -1
              SetActiveGadget(Cnt) : SendMessage_(GadgetID(GetActiveGadget()), #EM_SETSEL, 0, -1)
         Next Cnt
    EndIf

EndProcedure


Procedure FileSave()

    Protected Title$ , Text$

    Protected Cnt.i

    If CreateFile(0, "C:\PureBASIC\_____New___Source_Codes\valD.txt")     ;<--- change File Location and Name to your needs
         For Cnt = 1 To 2
              WriteStringN(0, GetGadgetText(Cnt))
         Next Cnt

         CloseFile(0)

         Title$ = "File Saved"
         Text$ = "Saved Location  :" + #CRLF$ + #CRLF$ + "C:\PureBASIC\_____New___Source_Codes\valD.txt"
         MessageRequester(Title$, Text$, #PB_MessageRequester_Ok)

         SetWindowTitle(#Window_0,"FileName :  valD.txt")
         SetActiveGadget(1)
    EndIf

EndProcedure


Procedure ClearAll()

    SetWindowTitle(#Window_0,"")          

    Var1 = 0 : Var2 = 0

    Protected Cnt.i
    For Cnt = 1 To 3
         SetGadgetText(Cnt,"")
    Next Cnt

    SetActiveGadget(1)

EndProcedure


Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 1:16 pm
by Vera
VB6_to_PBx wrote:i did a quick test using German Keyboard settings ... and it seems to work + save + open file correctly ?
Should work for most Countries Keyboard settings ?
It works fine for me.

Comma-separated values are read and changed to decimal-separated values.
Saving will write decimal-separated values to the file, ...
...EXCEPT if I save to file while one of the stringgadgets still contains a comma-separated value which had not been reset by a triggert event. [Test: type 2,34 into any stringgadget and save immediately.]

greets ~ Vera

Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 2:41 pm
by Little John
VB6_to_PBx wrote:i changed up the example Code considerably + adding new things

see if it works OK now ?
It does not work correctly. I still encounter the problem that is shown in falsam's post at the beginning of this thread.

You should change

Code: Select all

                   Var1 = ValD(GetGadgetText(1)) : CalcClear()
                   ;Var1 = ValD(ReplaceString( GetGadgetText(1),",",".")) : CalcClear()
to

Code: Select all

                   Var1 = ValD(ReplaceString( GetGadgetText(1),",",".")) : CalcClear()
(and the same with Var2)

Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 8:20 pm
by VB6_to_PBx
i changed this Code below to avoid input confusion

Code: Select all

Procedure CalcHelp()

    Protected Txt.s = #CRLF$ + #CRLF$ + "Enter a value between" + #CRLF$ + "if Decimal Keyboard = 1.0000 to 7.0000" + #CRLF$ + "if Comma Keyboard = 1,0000 to 7,0000"
    Protected HelpTxt.s

    Select EventGadget()
    Case 1 : HelpTxt = "Input Variable 1" + Txt
    Case 2 : HelpTxt = "Input Variable 2" + Txt
    EndSelect
    
    SetGadgetText(6,HelpTxt)

EndProcedure
if your Country uses Comma for decimal symbol then enter a value between 1,0000 to 7,0000
but if your Country uses Period for decimal symbol then enter a value between 1.0000 to 7.0000

with German keyboard setting does US-English 4.567 = 4,567 in German setting ??

when i enter 4,567 in both Var1 and Var2 StringGadets i get Answer = 20,8575 with German keyboard setting
and it saves valD.txt with 4,567 like :
valD.txt
4,5670
4,5670
this seems correct in German setting ??

i tried this with my Computer set to German keyboard settings

Code: Select all

Var1 = ValD(ReplaceString( GetGadgetText(1),",",".")) : CalcClear()
and it changes German Keyboard Commas into Decimal Points .... that seems wrong ??

Sorry for the hassle :)
i'm running my VB6.0 commerical Program i wrote side-by-side on same Win7 Computer along with the above PB Program ; Decimal_VS_Comma__test_v3.pb
and with German Keyboard setting and they both seem to show same results correctly on my end

maybe i need to test on different computer or OS
or reboot after changing Keyboard settings to German(Germany)

Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 8:44 pm
by Little John
VB6_to_PBx wrote:i tried this with my Computer set to German keyboard settings
This has nothing got to do with keyboard settings.
VB6_to_PBx wrote:

Code: Select all

Var1 = ValD(ReplaceString( GetGadgetText(1),",",".")) : CalcClear()
and it changes German Keyboard Commas into Decimal Points .... that seems wrong ??
ValD() interprets nothing else but a point as decimal separator, that's why you have to replace any comma before using ValD().
Sorry, is that actually so hard to understand? :x

Code: Select all

text$ = "1,23"
Debug ValD(text$)                            ; -> 1.0   (wrong)
Debug ValD(ReplaceString(text$, ",", "."))   ; -> 1.23  (OK)

Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 9:06 pm
by VB6_to_PBx
disregarding everything i've Posted :)

Then with Keyboard Country settings to German(Germany)

if you went to type a value in a Letter to someone or enter that in one of your own Programs
which one is correct in German(Germany) ??

1.23 ( with decimal )
or
1,23 ( with Comma )

Re: Decimal vs Comma will this work

Posted: Mon Jan 12, 2015 9:10 pm
by Little John
Obviously, you didn't understand the very simple and very basic stuff that I posted.
I give up trying to help you.