I'm trying to send this to SerialPort to command the devices' LED to lit on.
SData(0) = 85
SData(1) = 170
SData(2) = 36
SData(3) = 1
SData(4) = 2
SData(5) = 0
SData(6) = 1
SData(7) = 0
SData(8) = 0
SData(9) = 0
SData(10) = 0
SData(11) = 0
SData(12) = 0
SData(13) = 0
SData(14) = 0
SData(15) = 0
SData(16) = 0
SData(17) = 0
SData(18) = 0
SData(19) = 0
SData(20) = 0
SData(21) = 0
SData(22) = 39
SData(23) = 1
SerialPort1.Open()
For i = 0 To 23
SerialPort1.Write(Chr(SData(i)))
Next
SerialPort1.Close()
I don't get response from the device or anything. Then i noticed that the module freezes for 2 seconds, i think it's the loop.
I think i need to know the steps of how a SerialPort runs from open to close.
Btw, there's a original copy of this but it was in VB6
here's whats working: MSComm1.Output = Chr(SData(i))
Related
I am having some trouble with my vba code. It seems to be running in F8 but not in F5. When it runs in F5, item is not recognized (shows up as item = nothing). I have pasted the code below.
Sub SlicerSelect()
'On Error Resume Next
Worksheets("Sheet3").Activate
'Dim cache As Excel.SlicerCache
Dim item As SlicerItem
Dim Eval_Cell As String
Offset_Cell = Sheets("Sheet3").Range("A18").Address
A = 1: AA = 0: AAA = 0
For A = 1 To 2
AA = AA + 1
If AA = 1 Then
Slicer_Name = "Slicer_Color"
ElseIf AA = 2 Then
Slicer_Name = "Slicer_Letter"
End If
'Set cache = ActiveWorkbook.SlicerCaches(Slicer_Name)
BB = 0
Do Until End_Switch = 1
AAA = AAA + 1: BB = BB + 1: Eval_Cell = Range(Offset_Cell).Offset(0, CStr(AAA))
If BB = 1 Then
'''
Else
For Each item In ThisWorkbook.SlicerCaches(Slicer_Name).SlicerItems
If item.Name = Eval_Cell Then
item.Selected = True
Else
item.Selected = False
End If
Next item
End If
If IsEmpty(Eval_Cell) Then End_Switch = 1
Stop
Loop
End_Switch = 0
Next A
End Sub
I have to know what language is used here. In which language do we define a variable as $value = x
Does this language have loop controls? I need this information, can any one provide?
Public sub Annual_Leave()
$Decimal_Output1 = 0 //variables
$Decimal_Output2 = 0
IF #ServiceMonths# = 1 OR #ServiceMonths# = 2 THEN
$Decimal_Output1 = 0
ELSEIF #ServiceMonths# => 3 AND #ServiceMonths# <= 12 THEN
IF #ServiceMonths# = 3 THEN
$Decimal_Output1 = 1.7
END IF
ELSE
$Decimal_Output1 = 21
$Decimal_Output2 = 0
END IF
End sub
In Shadowrun 5e there is a rule concerning explosives in confined spaces called the 'Chunky Salsa Effect'. I am trying to create a program that simulates the 'Chunky Salsa Effect'. I have most of the program working, however, as the size of the space [meters] increases, the number of blast reflections [bounces] increases. It should be the inverse, the blast falloff [minusMeters] should decrease the [bounces]. [walls] determines the number of surfaces the blast reflects off of. [damageDice] is equal to the base damage of the explosive [baseDamageDice] + (([damageDice]/2) per reflection). For some reason [damageDice] and [bounces] do not decrease when [meters] is increased.
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim meters As Integer = 0
Dim dice As Integer = 0
Dim damageDice As Integer = 0
Dim baseDamageDice As Integer = 0
Dim bounces As Integer = 0
Dim hits As Integer = 0
Dim walls As Integer = 0
Dim minusMeters As Integer = 0
Dim explosiveType As Integer = 0
Dim ap As String = "-"
Dim diceRoll As Integer = 0
Randomize()
walls = CInt(txtWalls.Text)
explosiveType = cbExplosiveType.SelectedIndex
If explosiveType < 0 Then
explosiveType = 0
cbExplosiveType.SelectedIndex = 0
End If
Select Case explosiveType
Case 0
minusMeters = 1
baseDamageDice = 18
ap = "+5"
Case 1
minusMeters = 2
baseDamageDice = 16
ap = "-2"
Case 2
minusMeters = 4
baseDamageDice = 24
ap = "-4"
Case 3
minusMeters = 4
baseDamageDice = 24
ap = "-10"
Case 4
minusMeters = 1
baseDamageDice = 23
ap = "+5"
Case 5
minusMeters = 2
baseDamageDice = 21
ap = "-2"
End Select
diceRoll = CInt(Math.Floor((6 - 1 + 1) * Rnd())) + 1
If diceRoll >= 5 Then
hits = hits + 1
End If
dice = baseDamageDice
For x = 1 To walls
meters = CInt(txtMeters.Text)
damageDice = baseDamageDice
Do
damageDice = Math.Round(damageDice / 2)
dice = dice + damageDice
meters = meters - minusMeters
bounces = bounces + 1
Loop While meters >= 0
Next
For i As Integer = 1 To dice
diceRoll = CInt(Math.Floor((6 - 1 + 1) * Rnd())) + 1
If diceRoll >= 5 Then
hits = hits + 1
End If
Next
lblHitsPerBounce.Text = Math.Round(hits / bounces)
lblTimes.Text = bounces
lblResult.Text = dice
lblNumHits.Text = hits
lblAPOutput.Text = ap
End Sub
Is there a faster way to define the following variables. notAct is the name, after the name comes the cells positions. The "b" is for the column and the number refers to the row. The value is 0. Very single cell has to be defined so that I can use the variables.
Dim notAct_b1, notAct_c1, notAct_d1, ..., notAct_d20 As Integer
notAct_b1 = 0
notAct_c1 = 0
notAct_d1 = 0
notAct_b2 = 0
notAct_c2 = 0
notAct_d2 = 0
notAct_b3 = 0
notAct_c3 = 0
notAct_d3 = 0
notAct_b4 = 0
notAct_c4 = 0
notAct_d4 = 0
notAct_b5 = 0
notAct_c5 = 0
notAct_d5 = 0
notAct_b6 = 0
notAct_c6 = 0
notAct_d6 = 0
notAct_b7 = 0
notAct_c7 = 0
notAct_d7 = 0
notAct_b8 = 0
notAct_c8 = 0
notAct_d8 = 0
notAct_b9 = 0
notAct_c9 = 0
notAct_d9 = 0
notAct_b10 = 0
notAct_c10 = 0
notAct_d10 = 0
notAct_b11 = 0
notAct_c11 = 0
notAct_d11 = 0
notAct_b12 = 0
notAct_c12 = 0
notAct_d12 = 0
notAct_b13 = 0
notAct_c13 = 0
notAct_d13 = 0
notAct_b14 = 0
notAct_c14 = 0
notAct_d14 = 0
notAct_b15 = 0
notAct_c15 = 0
notAct_d15 = 0
notAct_b16 = 0
notAct_c16 = 0
notAct_d16 = 0
notAct_b17 = 0
notAct_c17 = 0
notAct_d17 = 0
notAct_b18 = 0
notAct_c18 = 0
notAct_d18 = 0
notAct_b19 = 0
notAct_c19 = 0
notAct_d19 = 0
notAct_b20 = 0
notAct_c20 = 0
notAct_d20 = 0
First of all, you don't need to initialize an Integer variable in VBA - it will be 0 after it is Dimmed.
However, instead of defining 4x20 variables, better use an array:
Dim notAct(1 to 20,1 to 43) As Integer
If you need to initialize or reset all values, you can use a small loop:
Dim col As Integer, row As Long
'Initialize/reset
For col = 1 To 4
For row = 1 To 20
notAct(row, col) = 0 'setting 0 not required after Dim
Next row
Next col
If you need to assign the value of a variable to a cell, use this syntax:
'Assigns a value from the array to B3
Cells(3, 2).Value = notAct(3, 2)
And best of all, if you want to assign all 4x20 cells with their values, use this one line of code:
Range("A1:D20").Value = notAct
I am new to VB.net and facing a strange situation. I have a structure that contains another structure. The inner structure is nullable. Now wht I do is something like the following. I create a new instance of the inner structure, set the member variables and assign the whole structure to the inner structure of the parent. But it is giving an error. The assignment is not successful. If I try to peek into the structure in the watch window, it says "property evaluation failed" for the HasValue and Value properties.
Dim testData As List(Of TestData) = Nothing
Dim testData_List1 As New TestData
With testData_List1.commonTestParam
.AccuchekActiveEnergy = 2.56
.AccuchekActiveEnergyUnit = ActiveEnergyUnit.KiloWattHour
.AccuchekApparentEnergy = 34.56
.AccuchekApparentEnergyUnit = ApparentEnergyUnit.VoltAmpereHour
.AccuchekFrequency = 1
.AccuchekRange = "20474 ewr 34324"
.AccuchekType = AccuchekType.AccuchekOne
.ActiveLoadRPhase = 145
.AvgActiveLoad = 2.56
.AvgActiveLoadUnit = ActiveLoadUnit.Watt
.AvgPowerFactor = 0
.AvgPowerFactorType = PowerFactorType.PFLag
.ConditionalFlag1 = 0
.ConsumerNo = "343122050242"
.CurrentRPhase = 1
.GeneralFlag1 = 0
.InstantaneousPFRPhase = 2
.ManufacturingYear = 2009
.MeterActiveEnergy = 258.89
.MeterActiveEnergyUnit = ActiveEnergyUnit.KiloWattHour
.MeterActiveError = 20
.MeterApparentError = 14
.MeterConstant = 3200
.MeterConstantUnit = MeterConstantUnit.RevsPerkVAh
.MeterMake = "DS"
.MeterSNo = "6563402"
.MeterTypeAndClass = MeterTypeAndClass.MTCElectorMechWith20
.MTFID = "123456789"
.NoofTestRevolutions = 100
.PulseCriteria = 0
.RatedBasic = 25
.RatedMax = 30
.RatedVoltage = 15
.ReactiveCurrentRPhase = 145
.RemarkID = 0
.TestDateAndTime = "100320101545"
.TestDuration = 2145
.TesterCode = 0
.TestID = "147852"
.TestMode = TestMode.TMOpticalScanner
.TestNumber = 0
.VoltageRPhase = 145
End With
Dim accuchek3TestParameters1 As New Accuchek3PhaseTestParameters
With accuchek3TestParameters1
.AccuchekReactiveLagEnergy = 2.46
.AccuchekReactiveLagEnergyUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.AccuchekReactiveLeadEnergy = 2.56
.AccuchekReactiveLeadEnergyUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.ActiveLoadBPhase = 14
.ActiveLoadYPhase = 15
.AvgApparentLoad = 10
.AvgApparentLoadUnit = ApparentLoadUnit.KiloVoltAmpere
.AvgReactiveLagLoad = 14
.AvgReactiveLagLoadUnit = ReactiveLoadUnit.KiloVoltAmpereReactive
.AvgReactiveLeadLoad = 15
.AvgReactiveLeadLoadUnit = ReactiveLoadUnit.KiloVoltAmpereReactive
.ConditionalFlag2 = 0
.ConditionalFlag3 = 0
.CTRatio = 1.23
.CurrentBPhase = 10
.CurrentYPhase = 11
.InstantaneousPFBPhase = 0
.InstantaneousPFYPhase = 1
.MeterApparentEnergy = 1.01
.MeterApparentUnit = ApparentEnergyUnit.KiloVoltAmpereHour
.MeterReactiveLagEnergy = 1.25
.MeterReactiveLagError = 1.25
.MeterReactiveLagUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.MeterReactiveLeadEnergy = 1.45
.MeterReactiveLeadError = 1.56
.MeterReactiveLeadUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.PercentageLoad = 1
.PTRatio = 1
.ReactiveCurrentBPhase = 10
.ReactiveCurrentYPhase = 11
.VoltageBPhase = 10
.VoltageYPhase = 10
End With
testData_List1.accuchek3TestParameters = accuchek3TestParameters1
testData.Add(testData_List1)
Can somebody please guide me?
Your first line is:
Dim testData As List(Of TestData) = Nothing
Then at the bottom you do
testData.Add(testData_List1)
I can't see anywhere in between where you do something like:
testData = New List(Of TestData)()
Though it's slightly hard to read since you've got both a variables and types with TestData as their name (or part of their name) so I might just be missing that.