I am getting solution errors when trying to run my application using the GmapControl package. Deleted the lines with errors does not seem to affect the application in any way but allows me to run the application, shortly after a while of debugging the lines reappear in the designer.vb file and the errors return.
Me.GMap.Bearing = 0!
Me.GMap.CanDragMap = True
Me.GMap.Dock = System.Windows.Forms.DockStyle.Fill
Me.GMap.EmptyTileColor = System.Drawing.Color.Navy
Me.GMap.GrayScaleMode = False
Me.GMap.HelperLineOption = GMap.NET.WindowsForms.HelperLineOptions.DontShow 'Error Line
Me.GMap.LevelsKeepInMemory = 5
Me.GMap.Location = New System.Drawing.Point(3, 3)
Me.GMap.MarkersEnabled = True
Me.GMap.MaxZoom = 2
Me.GMap.MinZoom = 2
Me.GMap.MouseWheelZoomEnabled = True
Me.GMap.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionAndCenter 'Error Line
Me.GMap.Name = "GMap"
Me.GMap.NegativeMode = False
Me.GMap.PolygonsEnabled = True
Me.GMap.RetryLoadTile = 0
Me.GMap.RoutesEnabled = True
Me.GMap.ScaleMode = GMap.NET.WindowsForms.ScaleModes.[Integer] 'Error Line
Me.GMap.SelectedAreaFillColor = System.Drawing.Color.FromArgb(CType(CType(33, Byte), Integer), CType(CType(65, Byte), Integer), CType(CType(105, Byte), Integer), CType(CType(225, Byte), Integer))
Me.GMap.ShowTileGridLines = False
Me.GMap.Size = New System.Drawing.Size(658, 455)
Me.GMap.TabIndex = 1
Me.GMap.Zoom = 0R
The problem is a name clash. GMap is a namespace and that is what .NET is a member of but you have added a GMapControl with the name GMap as well, so that is what the compiler is interpreting that name as. Notice how those lines all have Me.GMap on the left? The ones with GMap on the right are being interpreted as referring to that same GMapControl rather than the appropriate namespace. If you change the name of the control then the issue will go away.
You may need to either delete those lines first or edit them by hand afterwards though, because the rename may change the name of the namespace as well.
This is an example of why it's important to put some thought into your control and other names. If you use names that are descriptive in your specific scenario then name clashes are less likely.
Related
I'd like to disable text boxes if the SponName combo box contains certain company names. I thought I could try a for loop for this, but I'm not sure if I created the right variables or used the for loop properly. Please help!
I've tried cobbling together the following code from the threads below but can't quite adapt it to my problem. I'm still learning VBA and am not great with declaring variables. There's no error message, but the text fields just won't disable after updating SponName.
VBA code for if like multiple criteria
Private Sub SponName_AfterUpdate()
Dim sponcontains As Variant
sponcontains = SponName.Text
Criteria = Array("Company1*", "Company2*", "Company3*", "Company24*")
For i = LBound(Criteria) To UBound(Criteria)
If InStr(sponcontains, Criteria(i)) > 0 Then
cps_manufsite_name.Enabled = False
cps_manufsite_city.Enabled = False
cps_manufsite_st.Enabled = False
cps_manufsite_ctry.Enabled = False
Else
cps_manufsite_name.Enabled = True
cps_manufsite_city.Enabled = True
cps_manufsite_st.Enabled = True
cps_manufsite_ctry.Enabled = True
End If
Next i
End Sub
Use Text property only when control still has focus. You need Value property which is default for data controls so don't have to reference. Explicitly declare all variables. Should have Option Explicit at top of all modules. Set the VBA editor > Tools > Options > Require Variable Declaration to automatically add to new modules - will have to type into existing. Use of * wildcard not appropriate with InStr() function - it's just another literal character.
Like this - default value for Boolean variable is False:
Option Compare Database
Option Explicit
___________________________________________________________________________________
Private Sub SponName_AfterUpdate()
Dim sponcontains As Variant, criteria As Variant, booE As Boolean, i As Integer
sponcontains = Me.SponName
criteria = Array("Company1", "Company2", "Company3", "Company24")
For i = LBound(criteria) To UBound(criteria)
If InStr(sponcontains, criteria(i)) > 0 Then
booE = True
Exit For
End If
Next
cps_manufsite_name.Enabled = Not booE
cps_manufsite_city.Enabled = Not booE
cps_manufsite_st.Enabled = Not booE
cps_manufsite_ctry.Enabled = Not booE
End Sub
But your solution without loop is just as valid and most likely shorter. Again, use Boolean variable to set Enabled state instead of duplicating.
booE = InStr("Company1,Company2,Company3,Company24", Me.SponName) > 0
Consider what would happen if you had to modify this list. Would have to modify code and distribute new db version to users. Alternatively, use a table with an attribute (can be a yes/no field) for company status. Code can do a lookup to table. Better to use company ID value to search. Your combobox should have that as a column in its RowSource and usually that would be the combobox's value.
booE = DLookup("Status", "Companies", "CompanyID = " & Me.SponName)
Use of Conditional Formatting can often avoid VBA altogether.
I have created on Data Extractor application in Visual Studio 2019(VB.NET) which is scheduled to extract data from Access DB(updating by other software) file and convert to Text file in every 2 seconds. Meanwhile it also updates many controls of the form such as chart control, Progress Bar and Text box. I have published My application on .NET Framework 4.7.2
Issue:
Application is working Completely fine for almost an hour after initiation but its control started to fade and ultimately disappear after some time(As you can see in the image). Eventually it stopped responding and I have to close and reopen.
Ironically When I checked My text file during application under Hang condition, it was continuously updating with data from DB file. I suspected that code is performing its duty but Windows Form loses its aesthetics over the time. Why it is happening?
what could be the possible reason of occurrence? (I tried to clean the solution and built it again but gain no success)
I used CircularPeogressBar from https://github.com/RamsinChaabian/CircleProgressBar
Below is code from designer window
'CircularProgressBar1
'
Me.CircularProgressBar1.AccessibleRole = System.Windows.Forms.AccessibleRole.None
Me.CircularProgressBar1.AnimationFunction = WinFormAnimation.KnownAnimationFunctions.Liner
Me.CircularProgressBar1.AnimationSpeed = 0
Me.CircularProgressBar1.BackColor = System.Drawing.Color.Transparent
Me.CircularProgressBar1.Font = New System.Drawing.Font("Microsoft Sans Serif", 72.0!, System.Drawing.FontStyle.Bold)
Me.CircularProgressBar1.ForeColor = System.Drawing.Color.FromArgb(CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer))
Me.CircularProgressBar1.InnerColor = System.Drawing.Color.Transparent
Me.CircularProgressBar1.InnerMargin = 2
Me.CircularProgressBar1.InnerWidth = -1
Me.CircularProgressBar1.Location = New System.Drawing.Point(313, 132)
Me.CircularProgressBar1.MarqueeAnimationSpeed = 0
Me.CircularProgressBar1.Maximum = 60
Me.CircularProgressBar1.Name = "CircularProgressBar1"
Me.CircularProgressBar1.OuterColor = System.Drawing.Color.FromArgb(CType(CType(87, Byte), Integer), CType(CType(87, Byte), Integer), CType(CType(87, Byte), Integer))
Me.CircularProgressBar1.OuterMargin = -25
Me.CircularProgressBar1.OuterWidth = 25
Me.CircularProgressBar1.ProgressColor = System.Drawing.Color.Cyan
Me.CircularProgressBar1.ProgressWidth = 20
Me.CircularProgressBar1.SecondaryFont = New System.Drawing.Font("Microsoft Sans Serif", 36.0!)
Me.CircularProgressBar1.Size = New System.Drawing.Size(156, 156)
Me.CircularProgressBar1.StartAngle = -90
Me.CircularProgressBar1.Step = 1
Me.CircularProgressBar1.SubscriptColor = System.Drawing.Color.Transparent
Me.CircularProgressBar1.SubscriptMargin = New System.Windows.Forms.Padding(10, -35, 0, 0)
Me.CircularProgressBar1.SubscriptText = ""
Me.CircularProgressBar1.SuperscriptColor = System.Drawing.Color.Transparent
Me.CircularProgressBar1.SuperscriptMargin = New System.Windows.Forms.Padding(10, 35, 0, 0)
Me.CircularProgressBar1.SuperscriptText = ""
Me.CircularProgressBar1.TabIndex = 24
Me.CircularProgressBar1.TextMargin = New System.Windows.Forms.Padding(8, 8, 0, 0)
- Do I have to code entire CircularProgressBar Control to get rid of this issue or is there a way out available to tackle this problem?
- If proper dispose is the issue then how we can dispose them efficiently without leaking graphics resources?
I am trying to simplify this function which is similar from
Function Snake_makestep()
maincar.Location = locate(xpos, ypos)
car0.Location = locate(posx(0), posy(0))
car1.Location = locate(posx(1), posy(1))
If car2.Visible = True Then
car2.Location = locate(posx(2), posy(2))
End If
If car3.Visible = True Then
car3.Location = locate(posx(3), posy(3))
End If
If car4.Visible = True Then
car4.Location = locate(posx(4), posy(4))
End If
To
If car30.Visible = True Then
car30.Location = locate(posx(30), posy(30))
End If
End Function
I'm not sure If I can/how to use Controls.Find solution within this function. Any help?
To answer the question as asked:
For i = 2 To 30
Dim car = Controls("car" & i)
If car.Visible Then
car.Location = locate(posx(i), posy(i))
End If
Next
Visible and Location are both members of the Control class so it doesn't matter what type of control those car variables are.
Note that this assumes that all controls are on the form itself. If they are in a different parent container, you'd need to use the Controls collection of that container.
Also, I have started i at 2 there, so you'd still need the explicit code for car0 and car1. If they are always visible then you could start the loop at 0 and it would still work, saving you those two lines of code as well.
I am new to .net world, got some work to convert the VB 6 code to VB.net
where OptionLine is a LINE Control & intCurrentControlTop is a integer variable
'Create line
Load Line(count)
Line(count).Y1 = 20
Line(count).Y2 = 30
Line(count).X1 = Line(0).X1
Line(count).X2 = Line(0).X2
Line(count).Visible = True
when I am trying to convert the above code using VS2005 wizard, it treated Line variable as Label and give me below version
Line As Microsoft.VisualBasic.Compatibility.VB6.LabelArray
Line.Load(count)
Line(count).Y1 = 20
Line(count).Y2 = 30
Line(count).X1 = Line(0).X1
Line(count).X2 = Line(0).X2
Line(count).Visible = True
Now when I am compiling , Error = X1 is not a member of System.Windows.Forms.Label
can some one help
I have a DataGridView bound to a list of business objects:
Dim template As New IncidentTemplate
Dim temps As List(Of IncidentTemplate) = template.LoadAll
Dim bs As New BindingSource
If Not temps Is Nothing Then
bs.DataSource = temps
Me.dgvTemplates.DataSource = bs
End If
I then add an unbound button column and make some of the bound columns invisible:
Dim BtnCol As New DataGridViewButtonColumn
With BtnCol
.Name = "Edit"
.Text = "Edit"
.HeaderText = String.Empty
.ToolTipText = "Edit this Template"
.UseColumnTextForButtonValue = True
End With
.Columns.Add(BtnCol)
BtnCol = Nothing
For Each col As DataGridViewColumn In Me.dgvTemplates.Columns
Select Case col.Name
Case "Name"
col.DisplayIndex = 0
col.FillWeight = 100
col.Visible = True
Case "Description"
col.DisplayIndex = 1
col.FillWeight = 100
col.Visible = True
Case "Created"
col.DisplayIndex = 3
col.HeaderText = "Created On"
col.DefaultCellStyle.Format = "d"
col.FillWeight = 75
col.Visible = True
Case "CreatedBy"
col.DisplayIndex = 2
col.HeaderText = "Created By"
col.FillWeight = 75
col.Visible = True
Case "Edit"
col.DisplayIndex = 4
col.HeaderText = ""
col.FillWeight = 30
col.Visible = True
Case Else
col.Visible = False
End Select
Next
This seems to work reasonably well except no matter what I do the button column (Edit) always displays in the middle of the other columns instead of at the end. I've tried both DGV.Columns.Add and DGV.Columns.Insert as well as setting the DisplayIndex of the column (this works for all other columns) but I am unable to make the button column display in the correct location. I've also tried adding the button column both before and after setting the rest of the columns but this seems to make no difference Can anyone suggest what I am doing wrong? It's driving me crazy....
I stumbled on your post while looking to solve a similar problem. I finally tracked it down by doing as you mention (using the DisplayIndex property) and setting the AutoGenerateColumns property of the DataGridView to false. This property is not visible in the designer, so I just added it to the constructor for my form. Be sure to do this before setting the data source for your grid.
Hope this helps...
The AutoCreateColumn is the problem. The following article gives an example for how to fix it.
From DataDridView DisplayOrder Not Working
When setting the column’s DisplayIndex in a data grid view, some columns were out of order. To fix the issue, I had to set AutoGenerateColumns to true before setting the data source, and to FALSE after.
For Example:
dgvReservedStalls.AutoGenerateColumns = True
dgvReservedStalls.DataSource = clsReservedStalls.LoadDataTable()
dgvReservedStalls.AutoGenerateColumns = False
Same problem here, and after searching for a while, I found out that by setting the DisplayIndexes in Ascending order made it for me.
It's counter-intuitive, because it's a number, but I still had to set them in order.
This works:
With customersDataGridView
.Columns("ContactName").DisplayIndex = 0
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
.Columns("Country").DisplayIndex = 3
.Columns("CompanyName").DisplayIndex = 4
End With
While this did not:
With customersDataGridView
.Columns("ContactName").DisplayIndex = 0
.Columns("CompanyName").DisplayIndex = 4
.Columns("Country").DisplayIndex = 3
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
End With
I tried the above solutions without success. Then I found this article: It made it all better.
http://msdn.microsoft.com/en-us/library/vstudio/wkfe535h(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1