The code for the question "Sorting a range of values correctly in VBA" is below:
'Legend
Worksheets(1).Range("U1").Value = "Legend"
Worksheets(1).Range("U1:V1").Merge
'Classified Cases in Ranges
Worksheets(1).Range("U2:V2").Merge
Worksheets(1).Range("U2").Value = "Classified Cases in Ranges"
'Format the Legend
Worksheets(1).Range("U3:U40").NumberFormat = "#"
Worksheets(1).Range("V3:V40").NumberFormat = "#"
'Legend values
Worksheets(1).Range("U3").Value = 0
Worksheets(1).Range("U4").Value = 1
Worksheets(1).Range("U5").Value = 2
Worksheets(1).Range("U6").Value = 3
Worksheets(1).Range("U7").Value = 4
Worksheets(1).Range("U8").Value = 5
Worksheets(1).Range("U9").Value = 6
Worksheets(1).Range("U10").Value = 7
Worksheets(1).Range("U11").Value = 8
Worksheets(1).Range("U12").Value = 9
Worksheets(1).Range("U13").Value = 10
Worksheets(1).Range("U14").Value = 11
Worksheets(1).Range("U15").Value = 12
Worksheets(1).Range("U16").Value = 13
Worksheets(1).Range("U17").Value = 14
Worksheets(1).Range("U18").Value = 15
Worksheets(1).Range("U19").Value = 16
Worksheets(1).Range("U20").Value = 17
Worksheets(1).Range("U21").Value = 18
Worksheets(1).Range("U22").Value = 19
Worksheets(1).Range("U23").Value = 20
Worksheets(1).Range("U24").Value = 21
Worksheets(1).Range("U25").Value = 22
Worksheets(1).Range("U26").Value = 23
Worksheets(1).Range("U27").Value = 24
Worksheets(1).Range("U28").Value = 25
Worksheets(1).Range("U29").Value = 26
Worksheets(1).Range("U30").Value = 27
Worksheets(1).Range("U31").Value = 28
Worksheets(1).Range("U32").Value = 29
Worksheets(1).Range("U33").Value = 30
Worksheets(1).Range("U34").Value = 31
Worksheets(1).Range("U35").Value = 32
Worksheets(1).Range("U36").Value = 33
Worksheets(1).Range("U37").Value = 34
Worksheets(1).Range("U38").Value = 35
Worksheets(1).Range("U39").Value = 36
Worksheets(1).Range("U40").Value = "(blank)"
'Classified Cases in Ranges values
Worksheets(1).Range("V3").Value = "0-9"
Worksheets(1).Range("V4").Value = "10-19"
Worksheets(1).Range("V5").Value = "20-29"
Worksheets(1).Range("V6").Value = "30-39"
Worksheets(1).Range("V7").Value = "40-49"
Worksheets(1).Range("V8").Value = "50-59"
Worksheets(1).Range("V9").Value = "60-69"
Worksheets(1).Range("V10").Value = "70-79"
Worksheets(1).Range("V11").Value = "80-89"
Worksheets(1).Range("V12").Value = "90-99"
Worksheets(1).Range("V13").Value = "100-109"
Worksheets(1).Range("V14").Value = "110-119"
Worksheets(1).Range("V15").Value = "120-129"
Worksheets(1).Range("V16").Value = "130-139"
Worksheets(1).Range("V17").Value = "140-149"
Worksheets(1).Range("V18").Value = "150-159"
Worksheets(1).Range("V19").Value = "160-169"
Worksheets(1).Range("V20").Value = "170-179"
Worksheets(1).Range("V21").Value = "180-189"
Worksheets(1).Range("V22").Value = "190-199"
Worksheets(1).Range("V23").Value = "200-209"
Worksheets(1).Range("V24").Value = "210-219"
Worksheets(1).Range("V25").Value = "220-229"
Worksheets(1).Range("V26").Value = "230-239"
Worksheets(1).Range("V27").Value = "240-249"
Worksheets(1).Range("V28").Value = "250-259"
Worksheets(1).Range("V29").Value = "260-269"
Worksheets(1).Range("V30").Value = "270-279"
Worksheets(1).Range("V31").Value = "280-289"
Worksheets(1).Range("V32").Value = "290-299"
Worksheets(1).Range("V33").Value = "300-309"
Worksheets(1).Range("V34").Value = "310-319"
Worksheets(1).Range("V35").Value = "320-329"
Worksheets(1).Range("V36").Value = "330-339"
Worksheets(1).Range("V37").Value = "340-349"
Worksheets(1).Range("V38").Value = "350-359"
Worksheets(1).Range("V39").Value = ">=360"
Worksheets(1).Range("V40").Value = "(blank)"
'***************************************************
'***************************************************
'***************************************************
'Move to US MACRO worksheet
Worksheets(2).Activate
'Pivot Table 1
'Pivot Table 1
'Pivot Table 1
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
'Use vlookup() function and perform conditional formatting
For x = 4 To (LastRow - 1)
Cells(x, 1).FormulaR1C1 = "=VLOOKUP(RC[1],'US Master Macro'!R[-1]C[20]:R[36]C[21],2,FALSE)"
If Cells(x, 2) >= 8 Then
Cells(x, 1).Interior.ColorIndex = 3
Cells(x, 1).Font.ThemeColor = xlThemeColorDark1
Cells(x, 1).Font.Bold = True
Cells(x, 2).Interior.ColorIndex = 3
Cells(x, 2).Font.ThemeColor = xlThemeColorDark1
Cells(x, 2).Font.Bold = True
Cells(x, 3).Interior.ColorIndex = 3
Cells(x, 3).Font.ThemeColor = xlThemeColorDark1
Cells(x, 3).Font.Bold = True
Else
Cells(x, 1).Interior.ColorIndex = 2
End If
Next x
"I have the following data in a pivot table. To the left, is described a range and to the right the number of cells within that range. I would like to learn a code that correctly arranges the range in the left and color codes anything after "80-89". I have used the sort function but it doesn't seem to work. Please help."
Days Count of PR ID
"10-19" 656
"0-9" 480
"20-29" 190
"30-39" 115
"40-49" 65
"50-59" 47
"70-79" 28
"60-69" 23
"80-89" 12
"110-119" 3
"120-129" 2
"130-139" 1
"100-109" 1
"180-189" 1
I am trying to construct and If statement that turns a tab Red if two of three cells are colored, or Turns green if only on is colored. I was hoping that there would be an easier way to right it than three if statements like this.
Dim dateRng As String, num As Integer, j As Integer, irng As Range, frng As Range
dateRng = Sheets("Input Raw Data").Range("B" & counter + 2).Value
num = Sheets("Tool Setup").Range("C18").Value
NumPts = num * 3
For s = 1 To Sheets.Count
With Sheets(s)
For j = 1 To num
If .Name = j Then
.Range("A1:C1").Merge
.Range("A1") = dateRng
.Name = Sheets("Point Names").Range("B" & (3 * j - 1))
End If
Next j
End With
Next s
For s = 1 to Sheets.Count
With Sheets(s)
For y = 1 To NumPts
If .Name = Sheets("Reporting").Range("B" & (12 * y - 5)) Then
For k = 6 To -1
Set irng = Sheets("Reporting").Range("A" & (12 * y - k))
Set irng = Sheets("Reporting").Range(irng, irng.End(xlToRight).End(xlToRight))
irng.Copy (.Range("A2"))
Next k
.Columns("A:A").ColumnWidth = 12
.Columns("B:B").EntireColumn.AutoFit
If .Range("B7").Interior.ColorIndex > 0 Then
a = 1
End If
If .Range("B8").Interior.ColorIndex > 0 Then
a = a + 1
End If
If .Range("B9").Interior.ColorIndex > 0 Then
a = a + 1
End If
If a >= 2 Then
.Tab.ColorIndex = 3
ElseIf a <= 1 Then
.Tab.ColorIndex = 4
End If
End If
y = y + 2
Next y
End With
Next s
Something like this may help you. It still has multiple if statements. But the statements are simple and don't have to deal with how the combinations of different cells being colored.
Also, I used colorindex > 0 as the condition for having color filling.
a = 0
If .Range("B7").Interior.ColorIndex > 0 Then
a = 1
End If
If .Range("B8").Interior.ColorIndex > 0 Then
a = a + 1
End If
If .Range("B9").Interior.ColorIndex > 0 Then
a = a + 1
End If
If a = 2 Then
.Range("B10").Interior.ColorIndex = 3
ElseIf a = 1 Then
.Range("B10").Interior.ColorIndex = 43
End If
I have code that calculates stress at multiple points on a tank and then graphs these stresses on a Chart. I'll be viewing charts with no problem, and all of a sudden, the chart displays a red X and I need to close my program to view the stress results again.
I know there's no bug in my code. No exception is thrown. Any suggestions?
Public Sub Graph(Curves) 'Creates the Graphs
crtStressData.Series.Clear()
crtStressData.Legends.Clear()
'Dimension arrays for data points
FileClose()
Dim data As Double
Dim StressTitle As String
Dim k As Integer
Dim BorderSize As Integer = 4
'set up main graph
crtStressData.ChartAreas(0).CursorX.IsUserSelectionEnabled = True
crtStressData.ChartAreas(0).CursorY.IsUserSelectionEnabled = True
crtStressData.ChartAreas(0).AxisX.ScaleView.Zoomable = True
crtStressData.ChartAreas(0).AxisY.ScaleView.Zoomable = True
crtStressData.ChartAreas(0).AxisX.ScrollBar.IsPositionedInside = False
crtStressData.ChartAreas(0).AxisY.ScrollBar.IsPositionedInside = False
Dim LegendName As String = ""
StressTitle = TankName + " " + GraphType + " Stresses: " + strLoad + " Loading"
If GraphType = "Combined" Then
'Set component parameters
'Create Combined Graph
Call CreateDataPoints()
'Add title,
crtStressData.Titles(0).Text = StressTitle
For i = 0 To Curves - 1 'add legends
If i = 0 Then
LegendName = "Minimum Principal Stress"
ElseIf i = 1 Then
LegendName = "Minimum Principal Stress Location"
ElseIf i = 2 Then
LegendName = "Maximum Principal Stress"
ElseIf i = 3 Then
LegendName = "Maximum Principal Stress Location"
End If
crtStressData.Series.Add(LegendName)
''work on legend name
crtStressData.Series(i).ChartType = DataVisualization.Charting.SeriesChartType.Line 'sets as a line graph
crtStressData.Series(i).XAxisType = DataVisualization.Charting.AxisType.Primary
crtStressData.Series(i).YAxisType = DataVisualization.Charting.AxisType.Primary
crtStressData.Series(i).BorderWidth = BorderSize
For j = 0 To MaxDataPoints 'add points per legend type
'set up which data to add and define color
If i = 0 Then
' StressType(k) = "Minimum Principal Stress"
data = SMINMAXData(j)
color = Drawing.Color.Blue
ElseIf i = 1 Then
' StressType(k) = "Minimum Principal Stress Location"
data = SMINLOCData(j)
color = Drawing.Color.Green
ElseIf i = 2 Then
'StressType(k) = "Maximum Principal Stress"
data = SMAXMAXData(j)
color = Drawing.Color.DodgerBlue
ElseIf i = 3 Then
' StressType(k) = "Minimum Principal Stress Location"
data = SMAXLOCData(j)
color = Drawing.Color.Red
End If
'add data and color
crtStressData.Series(i).Points.AddXY(XPosData(j), data)
crtStressData.Series(i).Color = color
Next
k = k + 1
Next
Else ' GraphType = "Components"
crtStressData.Series.Clear()
'Set component parameters
'Create Component Graph
Call CreateDataPoints()
'Add title and axes labels
crtStressData.Titles(0).Text = StressTitle
For i = 0 To Curves - 1 'add legends
If i = 0 Then
LegendName = "Bending"
ElseIf i = 1 Then
LegendName = "Pressure (X)"
ElseIf i = 2 Then
LegendName = "Tension (X)"
ElseIf i = 3 Then
LegendName = "Total (X)"
ElseIf i = 4 Then
LegendName = "Pressure (Y)"
ElseIf i = 5 Then
LegendName = "Shear"
End If
crtStressData.Series.Add(LegendName) 'creates line
crtStressData.Series(i).ChartType = DataVisualization.Charting.SeriesChartType.Line 'sets as a line graph
crtStressData.Series(i).XAxisType = DataVisualization.Charting.AxisType.Primary
crtStressData.Series(i).YAxisType = DataVisualization.Charting.AxisType.Primary
crtStressData.Series(i).BorderWidth = BorderSize
For j = 0 To MaxDataPoints 'add points per legend
If i = 0 Then
'StressType(k) = "Bending"
data = SXBMAXData(j)
color = Drawing.Color.Blue
ElseIf i = 1 Then
' StressType(k) = "Pressure (X)"
data = SXPMAXData(j)
color = Drawing.Color.Green
ElseIf i = 2 Then
' StressType(k) = "Tension (X)"
data = SXTMAXData(j)
color = Drawing.Color.DodgerBlue
ElseIf i = 3 Then
'StressType(k) = "Total (X)"
data = SXMAXData(j)
color = Drawing.Color.Red
ElseIf i = 4 Then
' StressType(k) = "Pressure (Y)"
data = SYMAXData(j)
color = Drawing.Color.HotPink
ElseIf i = 5 Then
' StressType(k) = "Shear"
data = SSMAXData(j)
color = Drawing.Color.DarkOrange
End If
'add data and color
crtStressData.Series(i).Points.AddXY(XPosData(j), data)
crtStressData.Series(i).Color = color
Next
k = k + 1
Next
End If
'LEGEND
Dim StressLegend As Legend = New Legend()
StressLegend.IsDockedInsideChartArea = False
StressLegend.Docking = Docking.Bottom
StressLegend.Font = New Font("Gil Sans MT", 11)
StressLegend.TextWrapThreshold = 100
StressLegend.Alignment = StringAlignment.Center
crtStressData.Legends.Add(StressLegend)
crtStressData.Dock = DockStyle.None
crtStressData.Show()
End Sub
I want to control SAP from access to print a barcode label just by pressing a button in access.
Currently I have a script that only works if SAP is open
session.findById("wnd[0]/tbar[0]/okcd").Text ="pickLabel"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtY_P_MAT").Text = "testbox"
session.findById("wnd[0]/usr/txtY_P_QUA").Text = "1"
session.findById("wnd[0]/usr/ctxtY_P_LGN").Text = "test"
session.findById("wnd[0]/usr/ctxtY_P_PRI").Text = "testPrinter"
session.findById("wnd[0]/usr/txtY_P_KSC").Text = "test"
session.findById("wnd[0]/usr/txtY_P_KSC").SetFocus
session.findById("wnd[0]/usr/txtY_P_KSC").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
I would like to have a way to do it without having SAP open.
Also I need to record the barcode number, but in the screen this number is not shown.
Any idea?
Thanks!!!
I might have a solution for you.
I too needed SAP to print stickers on my Zebra Z4Mplus sticker printer.
What I did was use excel to generate my sticker and send them directly to the printer
First step was installing the printer, it is a TCP/IP printer that you have to connect directly to. The printer had a function to print all settings, I did that then used windows advanced printer setup, create a local TCP/IP port for the printer and added it. Google made this step easy.
Then in excel I inserted a chart on my worksheet.
then I created a shape and created the following code.
This code is an example, my code is much bigger, you need to generate all elements.
I used the GetPrinterFullNames function from pixcels.nl/set-activeprinter-excel/
For barcodes I used the following class stackoverflow.com/questions/13909248/generating-code-128-barcodes-using-excel-vba
You need to find the code128.fft file, I don't remember where I got it.
I also have a module for adding font to system without being administrator (using AddFontResource), storing font in excel worksheet
I got this module from this thread
http://www.mrexcel.com/forum/excel-questions/328457-how-do-you-embed-font-into-excel-file.html
So here is my code for printer my stickers.
Sub PrintExportControl()
Dim myprinter As String
Dim PrintersList() As String
Dim printer_name As String
Dim x As Long
GenerateExportControl
myprinter = Application.ActivePrinter
PrintersList() = GetPrinterFullNames
For x = 1 To UBound(PrintersList)
If InStr(1, PrintersList(x), "ExportControl", vbTextCompare) > 0 Then _
printer_name = PrintersList(x)
Next x
Application.ActivePrinter = printer_name
DoEvents
Sheet1.Shapes("chtExportControl").Chart.PrintOut , , , , "ExportControl"
Sheet1.Shapes("chtExportControl").Chart.PrintOut , , , , "ExportControl"
'Sheet1.Shapes("chtZSMI").Chart.PrintOut , , , , "ExportControl"
'Sheet1.Shapes("chtZSMI").Chart.PrintOut , , , , "ExportControl"
Application.ActivePrinter = myprinter
End Sub
And here is my code for generating the chart which has the sticker on it
Sub GenerateExportControl()
Dim mychart As Chart
Dim picLogo As Shape
Dim shpExportControl As Shape
Dim shpDate As Shape
Dim shpBadge As Shape
Dim shpPN As Shape
Dim shpSN As Shape
Dim shpESN As Shape
Dim shpPartDescription As Shape
Dim shpCSOrder As Shape
Dim shpSO As Shape
Dim shpCSOrderBarcode As Shape
Dim shpSOBarcode As Shape
Dim shp1stMil As Shape
Dim shpPUSML As Shape
Dim shpUSML As Shape
Dim shpITARCID As Shape
Dim shpPECCN As Shape
Dim shpECCN As Shape
Dim shpECL As Shape
' Get the TEMP path
Dim FSO As Object, TmpFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")
Set TmpFolder = FSO.GetSpecialFolder(2)
' Focus a cell
ActiveSheet.Range("A92").Select
' Make sure the "Code 128" font is available
If FontIsInstalled("Code 128") = False Then
CreateFontFile
AddFont
End If
Dim BarcodeGenerator As clsBarcode
Set BarcodeGenerator = New clsBarcode
Set mychart = Sheet1.Shapes("chtExportControl").Chart
mychart.Parent.Width = 288
mychart.Parent.Height = 144
mychart.ChartArea.Border.LineStyle = xlNone
For Each MyShape In mychart.Shapes
MyShape.Delete
Next
Set picLogo = mychart.Shapes.AddPicture("C:\Users\pw46487\Desktop\archive\programs\pwc-faded.jpg", msoTrue, msoTrue, 0, 0, 100, 79.39)
picLogo.Left = mychart.Parent.Width / 2 - picLogo.Width / 2
picLogo.Top = mychart.Parent.Height / 2 - picLogo.Height / 2
Set shpExportControl = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 181, 17)
shpExportControl.TextFrame.Characters.Text = "EXPORT CLASSIFICATION"
shpExportControl.TextFrame.Characters.Font.Size = 18
shpExportControl.TextFrame.MarginLeft = 0
shpExportControl.TextFrame.MarginTop = 0
shpExportControl.TextFrame.MarginRight = 0
shpExportControl.TextFrame.MarginBottom = 0
shpExportControl.TextFrame.AutoSize = True
Set shpDate = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 0, 61, 11)
shpDate.TextFrame.Characters.Text = Day(Date) & "-" & MonthName(Month(Date), True) & "-" & Year(Date)
If IsDate(Worksheets("Sheet1").Range("B68")) Then _
shpDate.TextFrame.Characters.Text = Day(Worksheets("Sheet1").Range("B68")) & "-" & _
MonthName(Month(Worksheets("Sheet1").Range("B68")), True) & "-" & _
Year(Worksheets("Sheet1").Range("B68"))
shpDate.TextFrame.Characters.Font.Size = 12
shpDate.TextFrame.MarginLeft = 0
shpDate.TextFrame.MarginTop = 0
shpDate.TextFrame.MarginRight = 0
shpDate.TextFrame.MarginBottom = 0
shpDate.TextFrame.AutoSize = True
shpDate.Left = ((mychart.Parent.Width - shpDate.Width - shpExportControl.Width) / 2) + shpExportControl.Left + shpExportControl.Width
Set shpBadge = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 0, 100, 11)
shpBadge.TextFrame.Characters.Text = "Badge: " & Split(Worksheets("Sheet1").Range("B11"), " ")(0)
shpBadge.TextFrame.Characters.Font.Size = 12
shpBadge.TextFrame.MarginLeft = 0
shpBadge.TextFrame.MarginTop = 0
shpBadge.TextFrame.MarginRight = 0
shpBadge.TextFrame.MarginBottom = 0
shpBadge.TextFrame.AutoSize = True
shpBadge.Top = shpDate.Top + shpDate.Height + 2
shpBadge.Left = ((mychart.Parent.Width - shpBadge.Width - shpExportControl.Width) / 2) + shpExportControl.Left + shpExportControl.Width
Set shpPN = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 4.5, 100, 11)
shpPN.TextFrame.Characters.Text = "PN: " & Worksheets("Sheet1").Range("B1")
shpPN.TextFrame.Characters.Font.Size = 11
shpPN.TextFrame.MarginLeft = 0
shpPN.TextFrame.MarginTop = 0
shpPN.TextFrame.MarginRight = 0
shpPN.TextFrame.MarginBottom = 0
shpPN.TextFrame.AutoSize = True
shpPN.Top = shpBadge.Top + shpBadge.Height - 2
shpPN.Left = mychart.Parent.Width - shpPN.Width
If Worksheets("Sheet1").Range("B1") = "" Then shpPN.Visible = False
Set shpSN = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 4.5, 100, 11)
shpSN.TextFrame.Characters.Text = "SN: " & Worksheets("Sheet1").Range("B4")
shpSN.TextFrame.Characters.Font.Size = 11
shpSN.TextFrame.MarginLeft = 0
shpSN.TextFrame.MarginTop = 0
shpSN.TextFrame.MarginRight = 0
shpSN.TextFrame.MarginBottom = 0
shpSN.TextFrame.AutoSize = True
shpSN.Top = shpPN.Top + shpPN.Height - 2
shpSN.Left = mychart.Parent.Width - shpSN.Width
If Worksheets("Sheet1").Range("B4") = "" Then shpSN.Visible = False
Set shpESN = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 4.5, 100, 11)
shpESN.TextFrame.Characters.Text = "ESN: " & Worksheets("Sheet1").Range("B5")
shpESN.TextFrame.Characters.Font.Size = 11
shpESN.TextFrame.MarginLeft = 0
shpESN.TextFrame.MarginTop = 0
shpESN.TextFrame.MarginRight = 0
shpESN.TextFrame.MarginBottom = 0
shpESN.TextFrame.AutoSize = True
shpESN.Top = shpSN.Top + shpSN.Height - 2
shpESN.Left = mychart.Parent.Width - shpESN.Width
If Worksheets("Sheet1").Range("B5") = "" Then shpESN.Visible = msoFalse
Set shpPartDescription = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 4.5, 100, 11)
shpPartDescription.TextFrame.Characters.Text = Worksheets("Sheet1").Range("B50")
shpPartDescription.TextFrame.Characters.Font.Size = 11
shpPartDescription.TextFrame.MarginLeft = 0
shpPartDescription.TextFrame.MarginTop = 0
shpPartDescription.TextFrame.MarginRight = 0
shpPartDescription.TextFrame.MarginBottom = 0
shpPartDescription.TextFrame.AutoSize = True
shpPartDescription.Top = mychart.Parent.Height - shpPartDescription.Height
shpPartDescription.Left = mychart.Parent.Width - shpPartDescription.Width
Set shpCSOrder = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 4.5, 100, 11)
shpCSOrder.TextFrame.Characters.Text = "CS:" & Worksheets("Sheet1").Range("B48")
shpCSOrder.TextFrame.Characters.Font.Size = 11
shpCSOrder.TextFrame.MarginLeft = 0
shpCSOrder.TextFrame.MarginTop = 0
shpCSOrder.TextFrame.MarginRight = 0
shpCSOrder.TextFrame.MarginBottom = 0
shpCSOrder.TextFrame.AutoSize = True
shpCSOrder.Top = shpPartDescription.Top - shpCSOrder.Height
shpCSOrder.Left = mychart.Parent.Width - shpCSOrder.Width
If Worksheets("Sheet1").Range("B48") = "" Then shpCSOrder.Visible = msoFalse
Sheet1.Shapes("chtBarcode2Pic").Chart.Shapes("TextBox 1").TextFrame.Characters.Text = BarcodeGenerator.Code128_Str(Worksheets("Sheet1").Range("B48"))
' Erase temporary file if exists
If FileExists(TmpFolder & "bufferbarcode.jpg") Then Kill TmpFolder & "bufferbarcode.jpg"
' Output picture of barcode to file
Sheet1.Shapes("chtBarcode2Pic").Chart.Export TmpFolder & "bufferbarcode.jpg", "jpg"
Set shpCSOrderBarcode = mychart.Shapes.AddPicture(TmpFolder & "bufferbarcode.jpg", msoTrue, msoTrue, 0, 0, 100, 22)
shpCSOrderBarcode.Top = shpCSOrder.Top - shpCSOrderBarcode.Height + 3
shpCSOrderBarcode.Left = mychart.Parent.Width - shpCSOrderBarcode.Width + 3
If Worksheets("Sheet1").Range("B48") = "" Then shpCSOrderBarcode.Visible = msoFalse
Set shpSO = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, 185, 4.5, 100, 11)
shpSO.TextFrame.Characters.Text = "SO:" & Worksheets("Sheet1").Range("B29")
shpSO.TextFrame.Characters.Font.Size = 11
shpSO.TextFrame.MarginLeft = 0
shpSO.TextFrame.MarginTop = 0
shpSO.TextFrame.MarginRight = 0
shpSO.TextFrame.MarginBottom = 0
shpSO.TextFrame.AutoSize = True
shpSO.Top = shpCSOrderBarcode.Top - shpSO.Height + 3
shpSO.Left = mychart.Parent.Width - shpSO.Width
If Worksheets("Sheet1").Range("B29") = "" Then shpSO.Visible = msoFalse
Sheet1.Shapes("chtBarcode2Pic").Chart.Shapes("TextBox 1").TextFrame.Characters.Text = BarcodeGenerator.Code128_Str(Worksheets("Sheet1").Range("B29"))
' Erase temporary file if exists
If FileExists(TmpFolder & "bufferbarcode.jpg") Then Kill TmpFolder & "bufferbarcode.jpg"
' Output picture of barcode to file
Sheet1.Shapes("chtBarcode2Pic").Chart.Export TmpFolder & "bufferbarcode.jpg", "jpg"
Set shpSOBarcode = mychart.Shapes.AddPicture(TmpFolder & "bufferbarcode.jpg", msoTrue, msoTrue, 0, 0, 100, 22)
shpSOBarcode.Top = shpSO.Top - shpSOBarcode.Height + 3
shpSOBarcode.Left = mychart.Parent.Width - shpSOBarcode.Width + 3
If Worksheets("Sheet1").Range("B29") = "" Then shpSOBarcode.Visible = msoFalse
Set shp1stMil = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shpExportControl.Top + shpExportControl.Height, 100, 11)
shp1stMil.TextFrame.Characters.Text = "1st MILITARY:(" & Worksheets("Sheet1").Range("B21") & ")"
shp1stMil.TextFrame.Characters.Font.Size = 13
shp1stMil.TextFrame.MarginLeft = 0
shp1stMil.TextFrame.MarginTop = 0
shp1stMil.TextFrame.MarginRight = 0
shp1stMil.TextFrame.MarginBottom = 0
shp1stMil.TextFrame.AutoSize = True
shp1stMil.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B21") = "" Then shp1stMil.Visible = msoFalse
Set shpPUSML = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shp1stMil.Top + shp1stMil.Height, 100, 11)
shpPUSML.TextFrame.Characters.Text = "P-USML:(" & Worksheets("Sheet1").Range("B22") & ")"
shpPUSML.TextFrame.Characters.Font.Size = 13
shpPUSML.TextFrame.MarginLeft = 0
shpPUSML.TextFrame.MarginTop = 0
shpPUSML.TextFrame.MarginRight = 0
shpPUSML.TextFrame.MarginBottom = 0
shpPUSML.TextFrame.AutoSize = True
shpPUSML.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B22") = "" Then shpPUSML.Visible = msoFalse
Set shpUSML = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shpPUSML.Top + shpPUSML.Height, 100, 11)
shpUSML.TextFrame.Characters.Text = "USML:(" & Worksheets("Sheet1").Range("B23") & ")"
shpUSML.TextFrame.Characters.Font.Size = 13
shpUSML.TextFrame.MarginLeft = 0
shpUSML.TextFrame.MarginTop = 0
shpUSML.TextFrame.MarginRight = 0
shpUSML.TextFrame.MarginBottom = 0
shpUSML.TextFrame.AutoSize = True
shpUSML.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B23") = "" Then shpUSML.Visible = msoFalse
Set shpITARCID = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shpUSML.Top + shpUSML.Height, 100, 11)
shpITARCID.TextFrame.Characters.Text = "ITAR CID:(" & Worksheets("Sheet1").Range("B24") & ")"
shpITARCID.TextFrame.Characters.Font.Size = 13
shpITARCID.TextFrame.MarginLeft = 0
shpITARCID.TextFrame.MarginTop = 0
shpITARCID.TextFrame.MarginRight = 0
shpITARCID.TextFrame.MarginBottom = 0
shpITARCID.TextFrame.AutoSize = True
shpITARCID.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B24") = "" Then shpITARCID.Visible = msoFalse
Set shpPECCN = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shpITARCID.Top + shpITARCID.Height, 100, 11)
shpPECCN.TextFrame.Characters.Text = "P-ECCN:(" & Worksheets("Sheet1").Range("B25") & ")"
shpPECCN.TextFrame.Characters.Font.Size = 13
shpPECCN.TextFrame.MarginLeft = 0
shpPECCN.TextFrame.MarginTop = 0
shpPECCN.TextFrame.MarginRight = 0
shpPECCN.TextFrame.MarginBottom = 0
shpPECCN.TextFrame.AutoSize = True
shpPECCN.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B25") = "" Then shpPECCN.Visible = msoFalse
Set shpECCN = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shpPECCN.Top + shpPECCN.Height, 100, 11)
shpECCN.TextFrame.Characters.Text = "ECCN:(" & Worksheets("Sheet1").Range("B26") & ")"
shpECCN.TextFrame.Characters.Font.Size = 13
shpECCN.TextFrame.MarginLeft = 0
shpECCN.TextFrame.MarginTop = 0
shpECCN.TextFrame.MarginRight = 0
shpECCN.TextFrame.MarginBottom = 0
shpECCN.TextFrame.AutoSize = True
shpECCN.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B26") = "" Then shpECCN.Visible = msoFalse
Set shpECL = mychart.Shapes.AddTextbox(msoTextOrientationHorizontal, shpExportControl.Left, shpECCN.Top + shpECCN.Height, 100, 11)
shpECL.TextFrame.Characters.Text = "ECL:(" & Worksheets("Sheet1").Range("B27") & ")"
shpECL.TextFrame.Characters.Font.Size = 13
shpECL.TextFrame.MarginLeft = 0
shpECL.TextFrame.MarginTop = 0
shpECL.TextFrame.MarginRight = 0
shpECL.TextFrame.MarginBottom = 0
shpECL.TextFrame.AutoSize = True
shpECL.Fill.BackColor.RGB = RGB(255, 255, 255)
If Worksheets("Sheet1").Range("B27") = "" Then shpECL.Visible = msoFalse
End Sub
Good luck
Please help I want to know exactly what is going on in this code for a questions and answers exam tomorrow.
I don't need any help with writing the code because that would be cheating. I made a tiny few mistakes please forgive me I rectified most of theses I don't need help with the mistakes just with the comments and understanding mostly how it works.
Private Sub Command1_Click()
MSComm1.Output = "83" + Chr$(13)
End Sub
Private Sub Form_Load()
MSC1.PortOpen = True
Average_val = 0
minimum_val = 255
maximum_val = 0
Screenshotofsinewave.Left = 0
Screenshotofsinewave.Channel(0).TraceVisible = True
Screenshotofsinewave.Channel(0).MarkersVisible = True
sumofall_val = 0
Screenshotofsinewave.TitleVisible = False
Screenshotofsinewave.Top = 0
Screenshotofrectifiedsinewave.TitleVisible = False
Screenshotofrectifiedsinewave.Channel(0).TraceVisible = True
Screenshotofrectifiedsinewave.Channel(0).MarkersVisible = True
Screenshotofrectifiedsinewave.Top = 0
Screenshotofrectifiedsinewave.Left = 0
Screenshotoflevelshiftedsinewave.Top = 0
Screenshotoflevelshiftedsinewave.Left = 0
Screenshotoflevelshiftedsinewave.TitleVisible = False
Screenshotoflevelshiftedsinewave.Channel(0).TraceVisible = True
Screenshotoflevelshiftedsinewave.Channel(0).MarkersVisible = True
End Sub
Private Sub MSC1_OnComm()
Dim number_val
Dim number1_val
Dim Average_val
Dim com1_val
p = 0
q = 0
r = 0
s = 0
t = 0
Dim Xarr(50) As Single
Dim Yarr(50) As Single
Dim number2_val
Dim number3_val
Dim Snapshotofsinewave
Dim string1_out As String
Dim string1_in As String
Dim counter As Single
Dim sample_rate As Integer
Select Case MSC1.CommEvent
Case comEvReceive
minimum_val = 255
string1_in = MSC1.Input
Screenshotofsinewave.Channel(0).Clear
Screenshotofrectifiedsinewave.Channel(0).Clear
Screenshotoflevelshiftedsinewave.Channel(0).Clear
counter = 0
comm_count = comm_count + 1
For sample_rate = 1 To 150 Step 3
string1_out = Mid(string1_in, sample_rate, 3)
counter = counter + 1
number_val = Val(string1_out)
Xarr(counter) = counter
Yarr(counter) = number_val
Screenshotofsinewave.Channel(0).AddXY counter, number_val
If number_val > maximum_val Then
maximum_val = number_val
MaxVoltage.Value = maximum_val
End If
If number_val < minimum_val Then
minimum_val = number_val
MinVoltage.Value = number_val
End If
sumofall_val = number_val + sumofall_val
Average_value = sumofall_val / 50
AverageVoltage.Value = Average_value
Next sample_rate
counter = 0
sumofall_val = 0
For sample_rate = 1 To 150 Step 3
string1_out = Mid(string1_in, sample_rate, 3)
counter = counter + 1
number_val = Val(string1_out)
number_val = number1_val - Average_value
number_val = numer_val
If num_val1 < 0 Then
number_val = number_val * -1
End If
Xarr(counter) = counter
Yarr(counter) = number1_val
Screenshotofrectifiedsinewave.Channel(0).AddXY counter, number1_val
Next sample_rate
counter = 0
For sample_rate = 1 To 150 Step 3
string1_out = Mid(string1_in, sample_rate, 3)
Count = Count + 1
number_val = Val(string1_out)
number2_val = number_val + Average_value
Xarr(Count) = counter
Yarr(Count) = number2_val
LevelShifted.Channel(0).AddXY Count, number_val2
sumofall_val = number_val + sumofall_val
Next sample_rate
counter = com1_val
Snapshotofsinewave.Value = com1_val
End Select
End Sub
Private Sub Frame4_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Uploaddata_Click()
If GXSwitch1.SwitchOn = True Then
led1.LampOn = True
p = 8
Else
led1.LampOn = False
p = 0
End If
If GXSwitch2.SwitchOn = True Then
led2.LampOn = True
q = 4
Else
led2.LampOn = False
q = 0
End If
If GXSwitch3.SwitchOn = True Then
led3.LampOn = True
r = 4
Else
led3.LampOn = False
r = 0
End If
If GXSwitch4.SwitchOn = True Then
led4.LampOn = True
s = 8
Else
led4.LampOn = False
s = 0
End If
t = p + q + r + s
If t = 0 Then
MSC1.Output = "0" + Chr$(13)
End If
If t = 1 Then
MSC1.Output = "1" + Chr$(13)
End If
If t = 2 Then
MSC1.Output = "2" + Chr$(13)
End If
If t = 3 Then
MSC1.Output = "3" + Chr$(13)
End If
If t = 4 Then
MSC1.Output = "4" + Chr$(13)
End If
If t = 5 Then
MSC1.Output = "5" + Chr$(13)
End If
If t = 6 Then
MSC1.Output = "6" + Chr$(13)
End If
If t = 7 Then
MSC1.Output = "7" + Chr$(13)
End If
If t = 8 Then
MSC1.Output = "8" + Chr$(13)
End If
If t = 9 Then
MSC1.Output = "9" + Chr$(13)
End If
If t = 10 Then
MSC1.Output = "10" + Chr$(13)
End If
If t = 11 Then
MSC1.Output = "11" + Chr$(13)
End If
If t = 12 Then
MSC1.Output = "12" + Chr$(13)
End If
If t = 13 Then
MSC1.Output = "13" + Chr$(13)
End If
If t = 14 Then
MSC1.Output = "14" + Chr$(13)
End If
If t = 15 Then
MSC1.Output = "15" + Chr$(13)
End If
End Sub
Depends on several factors...
Dim average_val, x As Decimal ' decimal
Dim average_val = 3.2D ' decimal if Option Infer On
Dim average_val = 3.2D ' object with boxed decimal if Option Infer Off
Dim average_val ' Object if Option Strict Off, otherwise an error