?? form1.frm
字號:
VERSION 5.00
Begin VB.Form Form1
Caption = "dBm和有效值轉換"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 5310
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 5310
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton Command2
Caption = "單位切換"
Height = 495
Left = 3600
TabIndex = 12
Top = 2400
Width = 975
End
Begin VB.Frame Frame1
Height = 975
Left = 3120
TabIndex = 4
Top = 480
Width = 1455
Begin VB.OptionButton Option_dBm2Vrms
Caption = "dBm->Vrms"
Height = 300
Index = 1
Left = 240
TabIndex = 6
Top = 600
Width = 1170
End
Begin VB.OptionButton Option_dBm2Vrms
Caption = "Vrms->dBm"
Height = 300
Index = 0
Left = 240
TabIndex = 5
Top = 240
Width = 1170
End
End
Begin VB.CommandButton Command1
Caption = "計算"
Height = 495
Left = 3600
TabIndex = 3
Top = 1680
Width = 975
End
Begin VB.TextBox Text_Ohm
Alignment = 1 'Right Justify
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1080
TabIndex = 1
Text = "50"
Top = 1380
Width = 855
End
Begin VB.TextBox Text_input
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1080
TabIndex = 0
Text = "0"
Top = 660
Width = 1095
End
Begin VB.Label Label_inputunit
Caption = "Vrms"
Height = 255
Left = 2280
TabIndex = 11
Top = 720
Width = 375
End
Begin VB.Label Label5
Caption = "Ω"
Height = 255
Left = 2040
TabIndex = 10
Top = 1440
Width = 255
End
Begin VB.Label Label4
Caption = "阻抗"
Height = 255
Left = 600
TabIndex = 9
Top = 1440
Width = 375
End
Begin VB.Label Label3
Caption = "輸入"
Height = 255
Left = 600
TabIndex = 8
Top = 720
Width = 375
End
Begin VB.Label Label2
Caption = "結果"
Height = 255
Left = 360
TabIndex = 7
Top = 2160
Width = 375
End
Begin VB.Label Label_output
BackColor = &H00C0FFFF&
BeginProperty Font
Name = "宋體"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 360
TabIndex = 2
Top = 2520
Width = 2655
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim cal_type As Boolean
Dim value_input As Double
Dim value_output As Double
Dim value_ohm As Single
Dim unit As Integer
Private Sub Command1_Click()
value_input = Val(Text_input.Text)
value_ohm = Val(Text_Ohm.Text)
If value_ohm = 0 Then
value_ohm = 0.001
Text_Ohm.Text = Format(0.001, "0.000")
End If
'Vrms->dBm
If cal_type = False Then
If value_input <= 0 Then
value_input = 0.001
Text_input.Text = Format(0.001, "0.000")
End If
value_output = 10 * Log10(value_input * value_input / value_ohm * 1000)
Label_output = Format(value_output, "0.000000") + " dBm"
'dBm->Vrms
Else
unit = 0
value_output = Sqr(Exp(value_input * Log(10) / 10) / 1000 * value_ohm)
Label_output = Format(value_output, "0.000000000") + " Vrms"
End If
End Sub
Private Sub Command2_Click()
If cal_type = True Then
value_input = Val(Text_input.Text)
value_ohm = Val(Text_Ohm.Text)
If value_ohm = 0 Then
value_ohm = 0.001
Text_Ohm.Text = Format(0.001, "0.000")
End If
value_output = Sqr(Exp(value_input * Log(10) / 10) / 1000 * value_ohm)
If unit = 0 Then
unit = 1
Label_output = Format(value_output * 1000#, "0.000000") + " mVrms"
ElseIf unit = 1 Then
unit = 2
Label_output = Format(value_output * 1000000#, "0.000") + " uVrms"
ElseIf unit = 2 Then
unit = 0
Label_output = Format(value_output, "0.000000000") + " Vrms"
End If
End If
End Sub
Private Sub Form_Load()
cal_type = 0
value_ohm = 50
value_output = 0
unit = 0
Text_input.Text = Format(1, "0.000000")
Option_dBm2Vrms.Item(0).Value = True
End Sub
Static Function Log10(X)
Log10 = Log(X) / Log(10#)
End Function
Private Sub Option_dBm2Vrms_Click(Index As Integer)
cal_type = Index
If cal_type = 0 Then
Label_inputunit.Caption = "Vrms"
Else
Label_inputunit.Caption = "dBm"
End If
Label_output = ""
End Sub
Private Sub Text_input_GotFocus()
If cal_type = False Then
Label_inputunit.Caption = "Vrms"
Else
Label_inputunit.Caption = "dBm"
End If
Label_output = ""
End Sub
Private Sub Text_input_KeyPress(KeyAscii As Integer)
'負號
If KeyAscii = 45 Then
If cal_type = 0 Then KeyAscii = 0
'小數點
ElseIf KeyAscii = 46 Then
ElseIf KeyAscii = vbKeyBack Then
'不接受數字鍵以外的鍵
ElseIf KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Private Sub Text_Ohm_KeyPress(KeyAscii As Integer)
'小數點
If KeyAscii = 46 Then
ElseIf KeyAscii = vbKeyBack Then
'不接受數字鍵以外的鍵
ElseIf KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -