這是我的第乙個教程,所以如果有任何錯誤,請原諒我=)。
這將為您展示一種非常簡單的方法,可從外部文字檔案中讀取登入資訊。
您需要什麼:
1.在專案中新增乙個新的「登入對話方塊」表單。
2.完全清除其中的**,但保留介面。
3.建立乙個文字檔案,其中一行一行地列出您的使用者名稱和密碼。
username1
password1
username2
password2
username3
password3
等等...
現在,將此**貼上到您的「登入」表單中。
dim nfilenum as integer, uinfo(999, 2) as string, snextline as string, llinecount as long, numline as integer, lcount as integer, unpw as integer, uncheck as boolean, pwcheck as boolean, usernum as integer
private sub form_load()
uncheck = false
pwcheck = false
nfilenum = freefile
open "c:\documents and settings\matt\my documents\testing.txt" for input as nfilenum
llinecount = 1
numline = 0
lcount = 1
unpw = 0
do while not eof(nfilenum)
line input #nfilenum, stext
lcount = lcount + 1
if lcount mod 2 <> 0 then unpw = 2
if lcount mod 2 = 0 then
numline = numline + 1
unpw = 1
end if
uinfo(numline, unpw) = stext
loop
end sub
private sub cmdcancel_click()
me.hide
endend sub
private sub cmdok_click()
'check for correct password
for x = 1 to lcount
if txtusername = uinfo(x, 1) then
uncheck = true
usernum = x
end if
next x
if txtpassword = uinfo(usernum, 2) then pwcheck = true
if txtusername = "" then
msgbox "invalid username or password, try again!", , "login"
txtpassword = ""
txtpassword.setfocus
sendkeys "+"
elseif txtpassword = "" then
msgbox "invalid username or password, try again!", , "login"
txtpassword = ""
txtpassword.setfocus
sendkeys "+"
elseif uncheck and pwcheck = true then
mainform.visible = true
me.enabled = false
me.hide
else
msgbox "invalid username or password, try again!", , "login"
txtpassword = ""
txtpassword.setfocus
sendkeys "+"
end if
end sub
現在,您快完成了。
1.轉到第9行,並將檔案路徑更改為文字檔案所在的位置。
2.轉到第55行,將「 mainform」更改為要顯示的表單。
現在您應該完成! 編寫程式的方式,您可能最多有999套使用者名稱和密碼。
from:
讀取文字檔案
void ctestdlg onreadinfo cfile filewrite1 testwrite1.txt cfile modecreate cfile modewrite cfile filewrite2 testwrite2.txt cfile modecreate cfile modew...
文字檔案從磁碟讀取 寫入
using system using system.text using system.io namespace x.common return result 寫入文字檔案,按預設編碼 文字檔案路徑包括檔名 寫入內容 public static void write string filepath,...
讀取文字檔案內容
讀取文字檔案內容 param filepathandname 帶有完整絕對路徑的檔名 param encoding 文字檔案開啟的編碼方式 return 返回文字檔案的內容 public string readtxt string filepathandname,string encoding th...