引用 | 編輯
troy_liaw106
2011-01-28 19:26 |
樓主
▼ |
||
|
引用 | 編輯
ebolaman
2011-01-28 22:19 |
1樓
▲ |
||||||||||
我之前在網路上看到有種方法,是用 For Each...Next 的方式來儲存與讀取
在此我做了個範例專案 關鍵的程式碼如下: 讀取部分: 複製程式 '------------------- For Each Ctl In Me tempInd = GetObjIndex(Ctl) tempName = GetCtlName(Ctl.Name, tempInd) m = DetectNamePlace(S, tempName) If m <> 0 Then '---------------- All Types of Objects -------------- On Error Resume Next Select Case TypeName(Ctl) Case "TextBox" Ctl.Text = GetValueAfterEqual(S, tempName, m) Case "CheckBox" Ctl.Value = GetValueAfterEqual(S, tempName, m) Case "OptionButton" Ctl.Value = GetValueAfterEqual(S, tempName, m) End Select '---------------------------------------------------- End If Next '------------------- 儲存部分: 複製程式 '------------------- For Each Ctl In Me '---------------- All Types of Objects -------------- Select Case TypeName(Ctl) Case "TextBox" tempS = Ctl.Text Case "CheckBox" tempS = Ctl.Value Case "OptionButton" tempS = Ctl.Value End Select '---------------------------------------------------- tempInd = GetObjIndex(Ctl) Print #f, GetCtlName(Ctl.Name, tempInd) & "=" & tempS Next '------------------- Control 是表單中所有可控制的元件 (控制項) 我加了很多 Function ,功能如下 (以下用 Ctl 簡稱控制項、S 簡稱 Set.ini 的內容): LoadEntireFile - 將某個檔案內的文字全部讀取 GetObjIndex - 傳回某 Ctl 的 Index ,不是群組物件則傳回 -1 GetCtlName - 將 Ctl 的名稱與 Index (如果有) 混合成標準的元件名稱 DetectNamePlace - 用 InStr 取得 元件名稱的設定值在 S 中的位置 GetValueAfterEqual - 取得 S 中某元件的數值 請參考此範例:
x1 |