請問下面一段程式碼是啥意思? 匿名使用者 1級 2019-01-01 回答

CString strImg;

CString strDire;

strImg。Empty();//字串值空

strDire。Empty();

strImg = m_TempPath;//將這個路徑字串賦值給strlmg

int nPos = strImg。ReverseFind(‘\\’);//在一個較大的字串中從末端開始查詢某個字元,返回位置

strDire = strImg。Left(nPos);//將該位置左側的字串賦值給strDire

nPos = strDire。ReverseFind(‘\\’);//以下兩行程式碼同樣

strDire = strDire。Left(nPos);

CTime timer;

timer = CTime::GetCurrentTime();//獲取當前時間

CString strTime;

strTime。Empty();//宣告的字串制空,初始化

strTime。Format(“\\CPK DAT\\%d%d%d%d%d%d。txt”,timer。GetYear(),timer。GetMonth(),timer。GetDay(),timer。GetHour(),timer。GetMinute(),timer。GetSecond());//strTime 賦值為 當前時間。txt

strDire +=strTime;路徑strDire賦值為 之前+當前時間。txt

這段程式碼意思應該是生成一個txt檔案的路徑

例如 c://windows//system 為 m_TempPath

結果就是 c://當前時間。txt

請問下面一段程式碼是啥意思? 匿名使用者 1級 2019-01-01 回答

int nPos = strImg。ReverseFind(‘\\’); 在string中查詢最後一個斜槓“\”,

strDire = strImg。Left(nPos); 然後擷取

timer = CTime::GetCurrentTime(); 獲取當前時間

trTime。Format(“\\CPK DAT\\%d%d%d%d%d%d。txt”,timer。GetYear(),timer。GetMonth(),timer。GetDay(),timer。GetHour(),timer。GetMinute(),timer。GetSecond()); 賦值

strDire +=strTime; 拼接

請問下面一段程式碼是啥意思? 幸福的兩個人 1級 2019-01-01 回答

樓上幹啥呢。。。

先把你程式碼整理下

private sub command1_click()

dim m() as long, i%, n%

if option1。value = true then

n = option1。caption

elseif option2。value = true then

n = option2。caption

elseif option3。value = true then

n = option3。caption

end if

redim m(i)

m(1) = 1

m(2) = 1

for i = 3 to n

m(i) = m(i - 1) + m(i - 2)

next i

text1。text = m(n)

end sub

樓主程式報錯應該是“下標越界”吧?錯誤在於這句:

redim m(i)

redim語句重新定義陣列的時候,陣列的引數要求必須是一個值或者是已經賦值的變數

而這裡你並沒有給變數 i 賦值,僅僅在程式開頭定義了 i ,所以程式預設你的 i 的值為0,所以你就相當於定義了一個數組m(0),只有一個元素的陣列,所以之後你給m(1)、m(2)賦值當然會報錯。

正確程式碼應該如下:

private sub command1_click()

dim m() as long, i%, n%

if option1。value = true then

n = option1。caption

elseif option2。value = true then

n = option2。caption

elseif option3。value = true then

n = option3。caption

end if

redim m(1 to n)

m(1) = 1

m(2) = 1

for i = 3 to n

m(i) = m(i - 1) + m(i - 2)

next i

text1。text = m(n)

end sub

經測試執行正確

搜狗問問

有問題的話歡迎追問 同時也歡迎加入我團哈~