1樓:刺友互
1、執行「microsoft visual studio 2010」。
2、」vs「的視窗彈出後,找到選單欄,滑鼠左鍵單擊標題為」檔案(f)「的選項。
3、在彈出的列表中滑鼠左鍵單擊標題為」新建專案(p)「的項。
4、在彈出的標題為」新建專案「,滑鼠左鍵選擇標題為」visual basic「項,在選擇標題為」windows「的項。再在右邊的列表中選擇標題為」windows 窗體應用程式「。
5、在一個背景為」白色"的視窗,且標題為「form1」的視窗中的空白處滑鼠左鍵雙擊。
6、在新切換到的「**編輯頁面」。
7、再在 「private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.
load」下寫**。就可以了。
2樓:問明
private sub form_click()dim dec as integer,base as integerdim decr(30)as integerdim strdecr as string*30dim strbase as string*16dim b as integer,n as integerstrbase="0123456789abcde"
dec=val(text1.text)
base=val(text2.text)
if base<2 or base>16 thenres=msgbox("進位制超出範圍",vbretrycancel)if res=vbretry then
text1.text=""
text1.setfocus
else
endend if
end if
n=0do while dec<>0
decr(n)=dec mod base
dec=dec\base
n=n+1
loop
strdecr=""
n=n-1
do while n>=0
b=decr(n)
strdecr=rtrim(strdecr)+mid(strbase,b+1,1)
n=n-1
loop
label3.caption=text1.text&"轉換為"&text2.text&"進位制後為:"
text3.text=strdecr
end sub
private sub form_load()label1.caption="十進位制數"
label2.caption="進位制"
label3.caption="以下是轉換結果:"
text1.text=""
text2.text=""
text3.text=""
end sub
3樓:澀果子
private sub command1_click()n = val(inputbox("輸入要轉換的十進位制整數:", "十進位制轉十六進位制", "16"))
m = n
x = ""
do while n >= 16
a = n mod 16
select case a
case is < 10
a = a
x = a & x
case is = 10
a = "a"
x = a & x
case is = 11
a = "b"
x = a & x
case is = 12
a = "c"
x = a & x
case is = 13
a = "d"
x = a & x
case is = 14
a = "e"
x = a & x
case is = 15
a = "f"
x = a & x
end select
n = n \ 16
loop
select case n
case is < 10
n = n
case is = 10
n = "a"
case is = 11
n = "b"
case is = 12
n = "c"
case is = 13
n = "d"
case is = 14
n = "e"
case is = 15
n = "f"
end select
b = x
x = n & x
msgbox m & "換成十六進位制數字是:" & x & " " & chr(10) & "a為:" & a & " " & chr(10) & "n為:
" & n & " " & chr(10) & "x為:" & b '輸出a,n,b是為了檢測方便
end sub
4樓:數學與計算機程式設計
此題,重點測試的是演算法設計,不宜使用vb系統定義的函式hex()。再說hex()函式只能將十進位制數轉化為十六進位制整數,而忽略十進位制數的小數部分,例如hex(123.652)=7b。
以下程式解決了hex()函式不能處理小數部分的問題。但我們知道很多十進位制小數不能轉化為有限位十六進位制小數,此時,本程式保留8位十六進位制小數,簡單修改本程式,即可改變保留的位數。
以下是程式**:
dim flag as boolean
private sub command1_click()
dim strarray(2) as string, valhexintegerpart() as integer, valhexdecimalpart() as integer
text2.text = ""
intarray = split(text1.text, ".")
intintegerpart = val(intarray(0))
if ubound(intarray) = 1 then
intdecimalpart = val("0." + intarray(1))
else
intdecimalpart = 0
end if
redim valhexintegerpart(len(intarray(0))), valhexdecimalpart(8)
debug.print intintegerpart, intdecimalpart
debug.print hex(intintegerpart)
do until intintegerpart = 0
valhexintegerpart(k) = intintegerpart mod 16
intintegerpart = intintegerpart \ 16
k = k + 1
loop
for i = k - 1 to 0 step -1
select case valhexintegerpart(i)
case 0 to 9
text2.text = text2.text + cstr(valhexintegerpart(i))
case 10 to 15
text2.text = text2.text + chr(valhexintegerpart(i) + 55)
end select
next i
k = 0
do until intdecimalpart = 0
valhexdecimalpart(k) = int(intdecimalpart * 16)
intdecimalpart = intdecimalpart * 16 - int(intdecimalpart * 16)
if k >= 8 then exit do
k = k + 1
loop
text2.text = text2.text + "."
for i = 0 to k - 1
select case valhexdecimalpart(i)
case 0 to 9
text2.text = text2.text + cstr(valhexdecimalpart(i))
case 10 to 15
text2.text = text2.text + chr(valhexdecimalpart(i) + 55)
end select
next i
end sub
private sub command2_click()
text1.text = ""
text2.text = ""
text1.setfocus
flag = false
end sub
private sub text1_keypress(keyascii as integer)
if not flag then
if not (keyascii >= asc("0") and keyascii <= asc("9")) and (keyascii <> 8) and (keyascii <> 46) then
keyascii = 0
beep
end if
else
if not (keyascii >= asc("0") and keyascii <= asc("9")) and keyascii <> 8 then
keyascii = 0
beep
end if
end if
if keyascii = 46 then
flag = true
end if
end sub
以下是執行介面:
5樓:三葉草
val("&h" & h)
6樓:匿名使用者
使用hex()函式即可:
x=hex(100)
vb中十進位制轉換成十六進位制的程式怎麼寫~
7樓:匿名使用者
private sub form_load()n = val(inputbox("請輸入要轉換的十進位制數整數"))m = n
x = "" :y=""
do while n <> 0
a = n mod 2
n = n \ 2
x = a & x
loop
msgbox m & "換成二進位制數是:" & xdo while len(x) mod 4 <> 0x = "0" + x
loop
do while len(x) > 0
select case right(x, 4)case "0000"
y= "0" + y
case "0001"
y= "1" + y
case "0010"
y = "2" + y
case "0011"
y = "3" + y
case "0100"
y = "4" + y
case "0101"
y = "5" + y
case "0110"
y = "6" + y
case "0111"
y = "7" + y
case "1000"
y = "8" + y
case "1001"
y = "9" + y
case "1010"
y = "a" + y
case "1011"
y = "b" +y
case "1100"
y = "c" + y
case "1101"
y = "d" + y
case "1110"
y = "e" + y
case "1111"
y = "f" + y
end select
x = left(x, len(x) - 4)loop
msgbox m & "換成十六進位制數是:" & yend sub
將十進位制數40轉換成二進位制求過程
40 2 20.0 5 2 2.12 2 1.01 2 0.1從下往上讀出所有的餘數,就是轉換成的二進位制數答案。將十進位制數193轉換成二進位制數過程,急求 十進位制整數轉換為二進位制整數採用 除2取餘,逆序排列 法。具體做法是 用2整除十進位制整數,可以得到一個商和餘數 再用2去除商,又會得到一...
十進位制的 12轉換成十六進位制是多少
大蘿蔔 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 a 11 b 12 c 13 d 14 e 15 f 如果是純計算的話,用這個表來 16 256 4096 65536 1048576 16777216 就是16 1 16 2 16 3 先找第一個比要轉的那個數小...
將二進位制101101101轉換成十進位制數怎麼轉換要
聖魔破天 二進位制轉化成十進位制的方法就是 每一位乘以二的這一位後面有幾位數的次方,例如 10就是,0位後面有0個數,所以就是0乘以2的0次方,1後面有1個數,所以就是1乘以2的1次方,最後所有結果相加就是最後轉換成的十進位制數 雨夜聽風過 101101101換算成 十進位制 第0位 1 2的0次方...