Есть файл, содержащий текст:
- Код: Выделить всё
Var1 = "v1"
Var2 = "v2"
Как эти значения присвоить переменным Var1 и Var2?
(Или как выполнить эти команды?)
Пробовал через ScriptControl, но он на такое не рассчитан...
Var1 = "v1"
Var2 = "v2"
Dim Var1 As String
Dim Var2 As String
Var1 = "v1"
Var2 = "v2"
4. Выделить из строк нужные значения
'Это содержимое файла:)
'Вернее, расшифрованное содержимое файла, оно у меня шифруется:)
StartNote = 4
GHour = 14
GDay = 1
GMon = 1
GYear = 2006
Score = 125
Money = "884900"
Status = 2
Work = 0
WorkX = 0
Nastr = 4
SysCase = True
MB = True
Proc = 19
RAM = 3
BP = True
VCard = 0
HD = 0
Monitor = 0
SCard = 0
Stereo = False
CDDVD = 0
KB = False
Mouse = 0
Modem = 0
Printer = 0
Scanner = False
IBP = False
CompWork = False
IntWork = False
InstList = ""
SoftList = ""
OS = 0
PName = "Дмитрий"
MonMoney = 0
IntTime = ""
Конь писал(а):StartNote = 4
GHour = 14
GDay = 1
GMon = 1
GYear = 2006
...
s = "var " & Replace(s, vbcrlf,";" & vbcrlf & "var ") & ";"
ЗЫ: а игра не в "апгрейд" случайно?
Public Function SaveKeyToIni(ByVal Path As String, ByVal Section As String, ByVal Key As String, ByVal Parameter As String)
Dim StartSection As Long
Dim StartKey As Long
StartSection = FindStringInFile(Path, 1, "[" & Section & "]", False)
'Stop
If StartSection = 0 Then
Open Path For Append As #1
If LOF(1) > 0 Then Print #1, ""
Print #1, "[" & Section & "]"
Print #1, Key & "=" & Parameter
Close #1
Else
StartKey = FindStringInFile(Path, StartSection, Key, False)
Dim tmpPath As String
Dim I As Integer
Dim J As Integer
Dim rByte As Byte
Dim wByte As Byte
'tmpPath = "C:\Documents and Settings\Nickon\Ðàáî÷èé ñòîë\" & "tmp_ini.tmp"
FileCopy Path, Environ("Temp") & "\" & "tmp_ini.tmp"
Open Path For Output As #2
Close #2
Open Environ("Temp") & "\" & "tmp_ini.tmp" For Binary As #1
Open Path For Binary As #2
If StartKey = 0 Then
For I = 1 To LOF(1)
Seek 1, I
Get #1, , rByte
Put #2, , rByte
If I = StartSection + Len("[" & Section & "]") - 1 Then
wByte = 13: Put #2, , wByte
wByte = 10: Put #2, , wByte
For J = 1 To Len(Key)
wByte = Asc(Mid(Key, J, 1))
Put #2, , wByte
Next J
wByte = Asc("="): Put #2, , wByte
For J = 1 To Len(Parameter)
wByte = Asc(Mid(Parameter, J, 1))
Put #2, , wByte
Next J
Seek 1, I + 1
Get #1, , rByte
If rByte <> 13 Then
wByte = 13: Put #2, , wByte
wByte = 10: Put #2, , wByte
End If
End If
Next I
Else
For I = 1 To LOF(1)
Seek 1, I
Get #1, , rByte
Put #2, , rByte
If I = StartKey + Len(Key) Then
For J = 1 To Len(Parameter)
wByte = Asc(Mid(Parameter, J, 1))
Put #2, , wByte
Next J
' Stop
For J = 1 To LOF(1) - Loc(2) + Len(Parameter)
Seek 1, I + J
Get #1, , rByte
If rByte = 13 Then I = I + J - 1: Exit For
Next J
End If
Next I
End If
Close #2
Close #1
Kill Environ("Temp") & "\" & "tmp_ini.tmp"
End If
End Function
Public Function LoadKeyFromIni(Path As String, Section As String, Key As String) As String
Dim I As Integer
Dim rByte As Byte
Dim rString As String
Dim StartSection As Long
Dim StartKey As Long
StartSection = FindStringInFile(Path, 1, Section, False)
StartKey = FindStringInFile(Path, StartSection, Key, False)
Open Path For Binary As #1
For I = 1 To LOF(1)
Seek 1, StartKey + I + Len(Key)
Get #1, , rByte
If rByte = 13 Then LoadKeyFromIni = rString: Exit For
rString = rString + Chr(rByte)
Next I
Close #1
End Function
Public Function FindStringInFile(Path As String, Start As Long, FindString As String, FindAllSections As Boolean) As Long
Dim I As Integer
Dim J As Integer
Dim rString As String
Dim rByte As Byte
Dim StartSection As Boolean
Open Path For Binary As #1
For I = Start To LOF(1) - 1
Seek 1, I
Get #1, , rByte
'Debug.Print Chr(rByte);
If StartSection = False And rByte = Asc("[") Then
StartSection = True
ElseIf StartSection = True And rByte = Asc("[") Then
'If FindAllSections = False Then
FindStringInFile = I
Exit For
'End If
End If
If rByte = Asc(Left(FindString, 1)) Then
rString = ""
For J = 0 To Len(FindString) - 1
Seek 1, I + J
Get #1, , rByte
rString = rString + Chr(rByte)
Next J
If UCase(rString) = UCase(FindString) Then FindStringInFile = I: Exit For Else FindStringInFile = 0
End If
Next I
Close #1
End Function
'declares for ini controlling
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
'// INI CONTROLLING PROCEDURES
'reads ini string
Public Function ReadIni(Filename As String, Section As String, Key As String) As String
Dim RetVal As String * 512, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 512, Filename)
ReadIni = Left(RetVal, v)
End Function
'reads ini section
Public Function ReadIniSection(Filename As String, Section As String) As String
Dim RetVal As String * 512, v As Long
v = GetPrivateProfileSection(Section, RetVal, 512, Filename)
ReadIniSection = Left(RetVal, v)
End Function
'writes ini
Public Sub WriteIni(Filename As String, Section As String, Key As String, Value As String)
WritePrivateProfileString Section, Key, Value, Filename
End Sub
'writes ini section
Public Sub WriteIniSection(Filename As String, Section As String, Value As String)
WritePrivateProfileSection Section, Value, Filename
End Sub
Private Function AddItem(Var As String) As Boolean
Dim arrvar() As String
Dim nCount As Integer
If Len(Var) = 0 Then Exit Function
arrvar = Split(Var, vbNewLine)
For nCount = 0 To UBound(arrvar)
listVar.AddItem arrvar(nCount)
Next nCount
AddItem = True
End Function
Ну значит и добавится такая вот фигня в лист...GB826 писал(а):vvs_adm, а если var=" "
Ну значит и добавится такая вот фигня в лист...
Интернет
Web Money
The Bat
RSS Feed Reader
I-net Money Counter
Твики
PowerTweakXP
IllusionLox
Private Function AddItem(ByVal sData As String) As Boolean
Dim iStart As Integer: iStart = 1
Dim iEnd As Integer: iEnd = 2
sData = IIf(Mid$(sData, 1, Len(vbNewLine)) = vbNewLine, "", vbNewLine) + sData + IIf(Right(sData, Len(vbNewLine)) = vbNewLine, "", vbNewLine)
Do
iEnd = InStr(iStart + 2, sData, vbNewLine): iStart = iEnd + 1: AddItem = True
listVar.AddItem Mid$(sData, iStart + 2, iEnd - iStart - 2)
If iEnd = Len(sData) - 1 Then Exit Do
Loop
End Function
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 80