ערכתי לאחרונה בתאריך 29.11.06 בשעה 14:15 בברכה, aaBlueDragon
תשמע, אין פקודה מיוחדת שעושה את זה.
מה שאתה צריך לדעת זה:
-שימוש בפקודה לכתיבה לתוך קובץ טקסט (קל מאוד)
-קריאה מתוך הטקסט, וביצוע SPLIT לכל מקום.
אתה קולט את הסטרינגים שעשית מהם SPLIT לתוך הערכים של התוכנה שלך.
אני מרשה לך להשתמש בקוד מקור של התוכנה שלי (DUKONNECTOR) על מנת לבצע
את מה שאתה רוצה.כך:
תעשה IMPORTS SYSTEM.IO
ותוסיף את הפונקציה הזאת לתוכנה שלך:
Public Function WriteTextToFile(ByVal PlaceAndName As String, ByVal WhatWrite As String, ByVal OverIt As Boolean) Dim objWriter As New System.IO.StreamWriter(PlaceAndName, OverIt) objWriter.Write(WhatWrite) objWriter.Close() Return Nothing End Function
|
עכשיו הנה הדרך שבה אני עושה זאת:
כך אני שומר לתוך הקובץ:
Public Function SaveSettings() WriteTextToFile(Application.StartupPath & "\Settings.ini", _ "This is Dukonnector's settings file." & vbCrLf & _ "all your settings are saved here." & vbCrLf & _ "if you dont know what you are doing please dont" & vbCrLf & _ "change any values because then the" & vbCrLf & _ "program might crash." & vbCrLf & _ "" & vbCrLf & _ "DukonnectorV=" & DukonnectorV & vbCrLf & _ "" & vbCrLf & _ "Player Profile:" & vbCrLf & _ "Nick Name=" & nickname & vbCrLf & _ "First Name=" & firstname & vbCrLf & _ "Last Name=" & lastname & vbCrLf & _ "Country=" & country & vbCrLf & _ "PlayMsgSound=" & PlayMsgSound & vbCrLf & _ "PlayJoinedSound=" & PlayJoinedSound & vbCrLf & _ "" & vbCrLf & _ "Directory Settings:" & vbCrLf & _ "EDuke32=" & eduke32dirstr & vbCrLf & _ "JFDuke=" & jfdukedirstr & vbCrLf & _ "Rancid Meat=" & rancidmeatdirstr & vbCrLf & _ "xDuke=" & xdukedirstr & vbCrLf & _ "UseExternalGRPDir=" & UseExternalGRPDir & vbCrLf & _ "GRPpath=" & GRPpath & vbCrLf & _ "Maps=" & mapdir & vbCrLf & _ "TCs=" & tcdir & vbCrLf & _ "" & vbCrLf & _ "Connection Settings:" & vbCrLf & _ "Mode=" & mode & vbCrLf & _ "SettingsAlwaysRenew=" & alwaysrenew & vbCrLf & _ "ExternalIP=" & userexternalip & vbCrLf & _ "LocalIP=" & userlocalip & vbCrLf & _ "ClientPort=" & userclientport & vbCrLf & _ "ServerPort=" & userserverport & vbCrLf & _ "" & vbCrLf & _ "Room Settings:" & vbCrLf & _ "RoomName=" & roomname & vbCrLf & _ "ServerGamePort=" & dukeExec & vbCrLf & _ "RoomType=" & roomtype & vbCrLf & _ "Players=" & playersam & vbCrLf & _ "GameType=" & gametype & vbCrLf & _ "Spawns=" & spawns & vbCrLf & _ "Monsters=" & monsters & vbCrLf & _ "Record=" & record & vbCrLf & _ "Connection=" & connection & vbCrLf & _ "MapType=" & maptype & vbCrLf & _ "MapName=" & mapname & vbCrLf & _ "AlwaysAdvertise=" & alwaysadv & vbCrLf & _ "" & vbCrLf & _ "Login Info:" & vbCrLf & _ "LoginType=" & logintype & vbCrLf & _ "UserName=" & UserName & vbCrLf & _ "Password=" & Password & vbCrLf & _ "" & vbCrLf & _ "Master Server Settings:" & vbCrLf & _ "msoption=" & msoption & vbCrLf & _ "mstextfile=" & mstextfile & vbCrLf & _ "msaddress=" & msaddress & vbCrLf & _ "End of file=", _ False) Return Nothing End Function
|
כך אני קורא מתוך הקובץ כאשר התוכנה נפתחת:
fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Settings.ini") Dim textoneline() As String Dim linesplitted() As String textoneline = fileContents.Split(vbCrLf) Dim i As Integer = 0 Do Try linesplitted = textoneline(i).Split("=") Catch i += 1 Continue Do End Try If linesplitted(0).Chars(0) = vbLf Then Dim splitted(2) As String splitted = linesplitted(0).Split(vbLf) linesplitted(0) = splitted(1) End If Select Case linesplitted(0) Case "Nick Name" nickname = linesplitted(1) Case "First Name" firstname = linesplitted(1) Case "Last Name" lastname = linesplitted(1) Case "Country" country = linesplitted(1) Case "EDuke32" eduke32dirstr = linesplitted(1) Case "JFDuke" jfdukedirstr = linesplitted(1) Case "Rancid Meat" rancidmeatdirstr = linesplitted(1) Case "xDuke" xdukedirstr = linesplitted(1) Case "Maps" mapdir = linesplitted(1) Case "TCs" tcdir = linesplitted(1) Case "Mode" mode = linesplitted(1) Case "SettingsAlwaysRenew" If playertype <> "CompOffline" Then alwaysrenew = linesplitted(1) If alwaysrenew = "True" Then userexternalip = FindExternalIP() userlocalip = FindLocalIP() If userlocalip <> FindGateWayIP() Then mode = "network" Else mode = "direct" End If ElseIf alwaysrenew = "Ex-Ip-Only" Then userexternalip = FindExternalIP() Else alwaysrenew = "False" End If End If Case "ExternalIP" If alwaysrenew = "False" Then userexternalip = linesplitted(1) End If Case "LocalIP" If alwaysrenew = "False" Then userlocalip = linesplitted(1) End If Case "ClientPort" userclientport = linesplitted(1) Case "ServerPort" userserverport = linesplitted(1) Case "RoomName" roomname = linesplitted(1) Case "ServerGamePort" dukeExec = linesplitted(1) Case "RoomType" roomtype = linesplitted(1) Case "Players" playersam = linesplitted(1) Case "GameType" gametype = linesplitted(1) Case "Spawns" spawns = linesplitted(1) Case "Monsters" monsters = linesplitted(1) Case "Record" record = linesplitted(1) Case "Connection" connection = linesplitted(1) Case "MapType" maptype = linesplitted(1) Case "MapName" mapname = linesplitted(1) Case "AlwaysAdvertise" alwaysadv = linesplitted(1) Case "PlayMsgSound" PlayMsgSound = linesplitted(1) Case "PlayJoinedSound" PlayJoinedSound = linesplitted(1) Case "UseExternalGRPDir" UseExternalGRPDir = linesplitted(1) Case "GRPpath" GRPpath = linesplitted(1) Case "End of file" Exit Do End Select i += 1 Loop While 0 = 0
|
כך נראה הקובץ אליו אני שומר את הנתונים:
This is Dukonnector's settings file. all your settings are saved here. if you dont know what you are doing please dont change any values because then the program might crash.DukonnectorV=0.61 Player Profile: Nick Name=jjjjj First Name=Duke Last Name=Nukem Country=Unknown PlayMsgSound=True PlayJoinedSound=True Directory Settings: EDuke32=C:\Games\RetexturedGames\Duke3d\EDuke32\eduke32.exe JFDuke= Rancid Meat= xDuke= UseExternalGRPDir=False GRPpath= Maps=c:\maps TCs=C:\TCs Connection Settings: Mode=network SettingsAlwaysRenew=True ExternalIP=88.152.118.206 LocalIP=192.168.0.108 ClientPort=4600 ServerPort=4601 Room Settings: RoomName=Newbie's Room ServerGamePort=EDuke32 RoomType=internet Players=4 GameType=DukeMatch (Spawn) Spawns=All Monsters=None Record=False Connection=Peer 2 Peer MapType=Epmap MapName= AlwaysAdvertise=True Login Info: LoginType=Choose UserName= Password= Master Server Settings: msoption=Text mstextfile=http://duke3d.vachu.com/msaddress.txt msaddress= End of file=
|