B4J Question Reading data @ start from an .ini textfile

GMan

Well-Known Member
Licensed User
Longtime User
I saved a single program parameter (the choosen COM-Port "dartport") in an .ini-file.
When i start the program again i wanted the COM-Port readed in automatically by B4J.

I did save the data this way, but no sense how to open it.
B4X:
Sub SetupSave_Action
    Dim res As Int = fx.Msgbox2(MainForm, "Änderrungen speichern ?", "Speichern", _
   "Ja", "Cancel", "Nein", fx.MSGBOX_WARNING)
If res = fx.DialogResponse.POSITIVE Then
   Log("Speichere Änderungen...")  
End If
' SPEICHERN
File.OpenOutput("C:\","Port.ini",True)
File.WriteString("C:\","Port.ini",dartport)   
SETUPpane.Visible= False
End Sub
 

GMan

Well-Known Member
Licensed User
Longtime User
Solved it - Erel did a great job with the preview of the correct syntax
Here's is my solution:

B4X:
    File.OpenInput("C:\","Port.ini")
    dartport = File.ReadString  ("C:\","Port.ini")   
     fx.Msgbox(MainForm, "Ausgewählter COM-Port", dartport)
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

some additional suggestions:
B4X:
Sub Process_Globals  ...
  Private dartport As String

B4X:
Sub SavePort
    Dim res As Int = fx.Msgbox2(MainForm, "Änderrungen speichern ?", "Speichern", "Ja", "Abbruch", "Nein", fx.MSGBOX_CONFIRMATION)
    If res = fx.DialogResponse.POSITIVE Then
        Log("Speichere Änderungen...")
        File.WriteString("C:\","port.ini",dartport)
        'ADD ANY MORE ACTIONS
    End If
End Sub

B4X:
Sub ReadPort
    dartport = File.ReadString("C:\","port.ini") 
    fx.Msgbox(MainForm, dartport, "Ausgewählter COM-Port")
End Sub
 
Last edited:
Upvote 0
Top