有谁可以为我解释这几段代码?1、2进制转换成10进制/10进制转换成2进制
Function N10to2(ByVal Number As Single) As SingleDim IntN As Long 'Number的整数部分
Dim FracN As Single 'Number的小数部分
Dim ModN As Integer '整数部分换算时,记录余数
Dim RltN As String '换算结果
Dim I As IntegerIf InStr(Number, "e") > 0 Or InStr(Number, "E") > 0 Then
Message = MsgBox("不能转换以科学记数法表示的数据", vbExclamation + vbOKOnly, "提示")
Exit Function
End IfModN = 0
'Number = Val(TextResult.Text)
IntN = Int(Number)
FracN = Number - IntN'以下代码用于将十进制的整数部分换算为二进制
Do While IntN > 0
ModN = IntN Mod 2
IntN = IntN \ 2
RltN = ModN & RltN
LoopRltN = RltN & "."
I = 1'以下代码用于将十进制的小数部分换算为二进制
Do While I <= 7 Or FracN <> 0
FracN = FracN * 2
If FracN >= 1 Then
FracN = FracN - 1
RltN = RltN & "1"
Else
RltN = RltN & "0"
End If
I = I + 1
LoopN10to2 = RltN
'Binarys.Value = True
End FunctionFunction N2to10(ByVal Number As Double) As Single
Dim I As Integer, J As Integer
Dim IntN As Long, FracN As Single
Dim RltN As Single
Dim POS As Integer '记录小数点位置If InStr(Number, "e") > 0 Or InStr(Number, "E") > 0 Then
Message = MsgBox("不能转换以科学记数法表示的数据", vbExclamation + vbOKOnly, "提示")
Exit Function
End IfOn Error GoTo Err
IntN = Int(Number)
FracN = Number - IntNDo While IntN > 0 '换算整数部分
RltN = RltN + (IntN Mod 10) * 2 ^ J
J = J + 1
IntN = IntN \ 10
LoopPOS = InStr(1, Str(FracN), ".")
J = -1
For I = POS + 1 To Len(Str(FracN)) '换算小数部分
RltN = RltN + 2 ^ J * Val(Mid(Str(FracN), I, 1))
J = J - 1
Next I
N2to10 = RltN
'Decimals.Value = True
Exit FunctionErr:
Message = MsgBox("数据溢出", vbExclamation + vbOKOnly, "提示")
End Function
2、水平翻转 和 垂直翻转
Drawing.PaintPicture Drawing.Picture, Drawing.ScaleWidth, 0, -Drawing.Width, Drawing.HeightDrawing.PaintPicture Drawing.Picture, 0, 0, Drawing.ScaleWidth, Drawing.ScaleHeight
3、关于计算圆心(Drawing 为 PictureBox)
xx = (x2 - x1) / 2 + x1 '计算圆心坐标
yy = (y2 - y1) / 2 + y1
r = IIf(Abs((x2 - x1) / 2) > Abs(y2 - y1) / 2, Abs((x2 - x1) / 2), Abs(y2 - y1) / 2) '椭园的半径
If x2 > x1 Then
Drawing.Circle (xx, yy), r, Drawing.BackColor, , , (Abs(y2 - y1) / 2) / (Abs((x2 - x1) / 2))
Drawing.Circle (xx, yy), r, , , , (Abs(y2 - y1) / 2) / (Abs((x2 - x1) / 2))
End If
xx = (X - x1) / 2 + x1
yy = (Y - y1) / 2 + y1
r = IIf(Abs((X - x1) / 2) > Abs(Y - y1) / 2, Abs((X - x1) / 2), Abs(Y - y1) / 2)
If X > x1 Then
Drawing.Circle (xx, yy), r, Drawing.BackColor, , , (Abs(Y - y1) / 2) / (Abs((X - x1) / 2))
Drawing.Circle (xx, yy), r, , , , (Abs(Y - y1) / 2) / (Abs((X - x1) / 2))
End If
x2 = X
y2 = Y
Function N10to2(ByVal Number As Single) As SingleDim IntN As Long 'Number的整数部分
Dim FracN As Single 'Number的小数部分
Dim ModN As Integer '整数部分换算时,记录余数
Dim RltN As String '换算结果
Dim I As IntegerIf InStr(Number, "e") > 0 Or InStr(Number, "E") > 0 Then
Message = MsgBox("不能转换以科学记数法表示的数据", vbExclamation + vbOKOnly, "提示")
Exit Function
End IfModN = 0
'Number = Val(TextResult.Text)
IntN = Int(Number)
FracN = Number - IntN'以下代码用于将十进制的整数部分换算为二进制
Do While IntN > 0
ModN = IntN Mod 2
IntN = IntN \ 2
RltN = ModN & RltN
LoopRltN = RltN & "."
I = 1'以下代码用于将十进制的小数部分换算为二进制
Do While I <= 7 Or FracN <> 0
FracN = FracN * 2
If FracN >= 1 Then
FracN = FracN - 1
RltN = RltN & "1"
Else
RltN = RltN & "0"
End If
I = I + 1
LoopN10to2 = RltN
'Binarys.Value = True
End FunctionFunction N2to10(ByVal Number As Double) As Single
Dim I As Integer, J As Integer
Dim IntN As Long, FracN As Single
Dim RltN As Single
Dim POS As Integer '记录小数点位置If InStr(Number, "e") > 0 Or InStr(Number, "E") > 0 Then
Message = MsgBox("不能转换以科学记数法表示的数据", vbExclamation + vbOKOnly, "提示")
Exit Function
End IfOn Error GoTo Err
IntN = Int(Number)
FracN = Number - IntNDo While IntN > 0 '换算整数部分
RltN = RltN + (IntN Mod 10) * 2 ^ J
J = J + 1
IntN = IntN \ 10
LoopPOS = InStr(1, Str(FracN), ".")
J = -1
For I = POS + 1 To Len(Str(FracN)) '换算小数部分
RltN = RltN + 2 ^ J * Val(Mid(Str(FracN), I, 1))
J = J - 1
Next I
N2to10 = RltN
'Decimals.Value = True
Exit FunctionErr:
Message = MsgBox("数据溢出", vbExclamation + vbOKOnly, "提示")
End Function
2、水平翻转 和 垂直翻转
Drawing.PaintPicture Drawing.Picture, Drawing.ScaleWidth, 0, -Drawing.Width, Drawing.HeightDrawing.PaintPicture Drawing.Picture, 0, 0, Drawing.ScaleWidth, Drawing.ScaleHeight
3、关于计算圆心(Drawing 为 PictureBox)
xx = (x2 - x1) / 2 + x1 '计算圆心坐标
yy = (y2 - y1) / 2 + y1
r = IIf(Abs((x2 - x1) / 2) > Abs(y2 - y1) / 2, Abs((x2 - x1) / 2), Abs(y2 - y1) / 2) '椭园的半径
If x2 > x1 Then
Drawing.Circle (xx, yy), r, Drawing.BackColor, , , (Abs(y2 - y1) / 2) / (Abs((x2 - x1) / 2))
Drawing.Circle (xx, yy), r, , , , (Abs(y2 - y1) / 2) / (Abs((x2 - x1) / 2))
End If
xx = (X - x1) / 2 + x1
yy = (Y - y1) / 2 + y1
r = IIf(Abs((X - x1) / 2) > Abs(Y - y1) / 2, Abs((X - x1) / 2), Abs(Y - y1) / 2)
If X > x1 Then
Drawing.Circle (xx, yy), r, Drawing.BackColor, , , (Abs(Y - y1) / 2) / (Abs((X - x1) / 2))
Drawing.Circle (xx, yy), r, , , , (Abs(Y - y1) / 2) / (Abs((X - x1) / 2))
End If
x2 = X
y2 = Y
解决方案 »
- 急啊,webbrowser 报错
- 32位程序能否在vista下运行
- 数据采集器
- 我想在菜單欄右邊加一個按鈕,請教各位高手
- Why the Webbrowser ocx is not XP style even any other ocxes in my program has already turned xp style after attached *.manifest!
- 如何去掉 ListBox 中垂直滚动条?
- 源代码求购
- 在程序中调用完EXCEL如何使EXCEL完全关闭?
- 有重要问题请教
- API从何学起啊?~~~~~~
- 请问那里有酒店管理系统源码下载,我真在做,我想下个源码参考
- vb+crystal report9.0+sql 高手请进 看看我的代码有何不当(急!)
PaintPicture 語法解釋:
object.PaintPicture picture, x1, y1, width1, height1, x2, y2, width2,height2, opcode(這是全部敘述)。
object :你要畫圖的 Target 物件,這裏應是 Picture1
picture: 你要畫圖的 Source 物件,這裏應是 Picture2
x1, y1 從 Target 物件的那個座標開始畫。
width1, height1 在Target 物件上畫多長多寬。
x2, y2 從 Source 物件的那個座標開始取圖樣。
width2, height2 要取多長多寬的圖
opcode 貼圖模式,與 picture.drawmode 同義,如果你不做什麼特殊效果可以不填。
如何區塊取圖及貼圖:
現在假設我們要取 Picture2 左下角,20 平方點的圖貼在 picture1 的右上角,那指令是這樣下:picture1.paintpicture picture2.picture,picture1.scalewidth-20,0,20,20,0,picture2.scaleheight-20,20,20兩個 picturebox.scalemode 要一樣,最好設為像素。第三个:计算椭圆的圆心
xx = (x2 - x1) / 2 + x1 '计算圆心坐标
yy = (y2 - y1) / 2 + y1
r = IIf(Abs((x2 - x1) / 2) > Abs(y2 - y1) / 2, Abs((x2 - x1) / 2), Abs(y2 - y1) / 2) '椭园的半径
If x2 > x1 Then
Drawing.Circle (xx, yy), r, Drawing.BackColor, , , (Abs(y2 - y1) / 2) / (Abs((x2 - x1) / 2))
Drawing.Circle (xx, yy), r, , , , (Abs(y2 - y1) / 2) / (Abs((x2 - x1) / 2))
End If
xx = (X - x1) / 2 + x1
yy = (Y - y1) / 2 + y1
r = IIf(Abs((X - x1) / 2) > Abs(Y - y1) / 2, Abs((X - x1) / 2), Abs(Y - y1) / 2)
If X > x1 Then
Drawing.Circle (xx, yy), r, Drawing.BackColor, , , (Abs(Y - y1) / 2) / (Abs((X - x1) / 2))
Drawing.Circle (xx, yy), r, , , , (Abs(Y - y1) / 2) / (Abs((X - x1) / 2))
End If
x2 = X
y2 = Y
谁能解释这段代码的意思,我就给65分(或更多),非常急,请各位高手帮忙
x1=起点 X 坐标
y1=起点 Y 坐标
x2=记录上一次 起点 X 坐标
y2=记录上一次 起点 Y 坐标
X=当前鼠标 X 坐标
Y=当前鼠标 Y 坐标
r=圆的半径