Date in Userform Text.Box not showing the data inserted - vba

i have a simple userform with a textbox where the user inserts a date and another textbox where the user inserts a number. When i try to use the data from the form it will not show the inserted data: the date shows as 12:00:00 am and the numeber shows as 0 .
Here is the userform
Public Sub CancelButton_Click()
Unload Me
End
End Sub
Public Sub UserForm_Initialize()
TextBox1.Value = ""
TextBox2.Value = ""
End Sub
Public Sub btnOK_Click()
Dim xSO As Date
Dim ySO As String
xSO = Format(TimeValue(TextBox1.Value), "dd.mm.yyyy")
ySO = TextBox2.Value
Unload Me
End Sub
Here is the minimum sub:
Public xSO As Long, ySO As Long
Sub ffffff()
Dim x As Date, y As String
UserForm19.Show
x = xSO 'Format(TextBox1.Value, "dd.mm.yyyy")
y = ySO 'UserForm19.TextBox2.text
MsgBox x
MsgBox y
End Sub

You declared xSO and ySO twice.
Remove the local declaration from Public Sub btnOK_Click()
Dim xSO As Date
Dim ySO As String

Related

load and unload form as a string passed to a sub

hi I would like to load and unload a user form by calling formtimer with a string as the form name
not sure how I would go about it ,i would love some input
Public Sub callme()
FormTimer ("UserForm1")
End Sub
public Sub FormTimer(Fname As String)
Fname.Show vbModeless
Application.OnTime Now + TimeValue("00:00:02"), "UnloadIt(Fname)"
End Sub
Public Sub UnloadIt(name As string)
Unload name
End Sub
Try the following code...
Public Sub callme()
FormTimer "UserForm1"
End Sub
Public Sub FormTimer(Fname As String)
VBA.UserForms.Add(Fname).Show vbModeless
Application.OnTime Now + TimeValue("00:00:02"), "'UnloadIt """ & Fname & """'"
End Sub
Public Sub UnloadIt(name As String)
Dim uf As Object
For Each uf In VBA.UserForms
If uf.name = name Then
Unload uf
Exit Sub
End If
Next uf
End Sub

Vb.net bindingsource.filter from a list of strings

i have in a windows.form a combobox and a datagridview,
i add rows in datagridview with a button and get the value(string) from combobox and if i double click on the row of datagridview i delete the row.
When i add the row i want to hide/disable/remove the combobox value and when i delete the row i want to restore it in combobox.
The combobox values are binding from dataset source and combobox is dropdownlist style.
I try some things until now but this is what i think is better approach and where i am:
Dim filterList As List(Of String) = New List(Of String)
Private Sub filterListAdd()
Dim dgResult As String
filterList .Clear() 'Clear the list so no duplicates
For i As Integer = 0 To combobox.Items.Count - 1
Dim a As String = combobox.GetItemText(combobox.Items(i))
For row As Integer = 0 To Dgview.RowCount - 1
For col As Integer = 0 To Dgview.ColumnCount - 1
Next
Surname = Dgview.Rows(row).Cells(0).Value.ToString
If dgResult = a Then
filterList .Add(a) 'Add to list
End If
Next
Next i
End Sub
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
Dgview.Rows.Add(combobox.Text)
filterListAdd()
'Here i want to bindingsource.filter = filterList
End Sub
Private Sub Dgview_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Dgview.MouseDoubleClick
Dgview.Rows.Remove(Dgview.CurrentRow)
'I Guess here with the same way i filter it again
End Sub
Any help will be appreciated, thanks in advance.
Panos
Public Class Form1
Dim clsItems As New ArrayList()
Private Sub RemoveComboItem()
Me.BindingSource.Position = Me.BindingSource.Find("1", Combobox.Text)
Dim 1Add As String = DirectCast(BindingSource.Current, DataRowView).Item("1").ToString
Dim 2Add As String = DirectCast(BindingSource.Current, DataRowView).Item("2").ToString
Dim 3Add As String = DirectCast(BindingSource.Current, DataRowView).Item("3").ToString
clsItems.Add(New MyItem(1Add, 2Add, 3Add))
BindingSource.RemoveCurrent()
End Sub
Private Sub AddComboItem(dg As DataGridView) ' Because i have two datagridviews
Dim 1 As String = dg.CurrentRow.Cells(0).Value.ToString()
For i = 0 To clsItems.Count - 1
If i <= clsItems.Count - 1 Then
If 1 = clsItems(i).1 Then
Dim drNewRow As DataRow
drNewRow = DeeDataSet.Tables("Table").NewRow()
drNewRow("1") = clsItems(i).1
drNewRow("2") = clsItems(i).2
drNewRow("3") = clsItems(i).3
DeeDataSet.Tables("Table").Rows.Add(drNewRow)
clsItems.Remove(clsItems(i)) ' Remove it from array so no duplicates
End If
End If
Next
End Sub
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
RemoveComboItem()
End Sub
Private Sub Dgview_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Dgview.MouseDoubleClick
AddComboItem(Dgview)
Dgview.Rows.Remove(Dgview.CurrentRow)
End Sub
End class
Public Class MyItem
Private m_s1 As String
Private m_s2 As String
Private m_s3 As String
Public Sub New(1As String, 2 As String, 3 As String)
M_sName = 1
M_sSurname = 2
M_sTitle = 3
End Sub
Public ReadOnly Property 1
Get
Return m_s1
End Get
End Property
Public ReadOnly Property 2
Get
Return M_s2
End Get
End Property
Public ReadOnly Property 3
Get
Return M_s3
End Get
End Property
End Class
In that form i don't update the dataset because every change i want to make it in other form, so when i finish from here the dataset.table has no changes.

function that runs when dynamically generated control is interacted with

I've been Having trouble with making a sub that runs when my datagridview cell is doubleclicked. It is caused because the datagridview is programmatically created, rather than created by the designer. I have found a help website i will include that appears to be related to the issue.
Public Class seattemplatecreator
Dim alphabet() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()
Private WithEvents dgv_flightTemplate As DataGridView
'help from https://it.toolbox.com/question/event-for-dynamically-created-command-button-043008
Public Sub init(ByVal dgv01 As DataGridView)
dgv_flightTemplate = dgv01
End Sub
Private Sub dgv_flightTemplate_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv_flightTemplate.CellMouseDoubleClick
MsgBox("workwd")
End Sub
Private Sub btn_createflight_Click(sender As Object, e As EventArgs) Handles btn_createflight.Click
'used https://social.msdn.microsoft.com/Forums/vstudio/en-US/e222f438-f060-4e61-ab28-523d02db91b2/how-to-programmatically-create-datagridview-with-empty-columns-and-rows?forum=vbgeneral
'to help with this part for automatically generating the datagridview
MsgBox(alphabet(0))
Dim dgv_flightTemplate As New DataGridView
Dim c As Integer = txb_columns.Text
Dim r As Integer = txb_rows.Text
For colcount As Integer = 0 To c - 1
Dim nc As New DataGridViewTextBoxColumn
nc.Name = "Seating Column"
dgv_flightTemplate.Columns.Add(nc)
Next
dgv_flightTemplate.Rows.Add(r)
For x = 0 To r - 1
dgv_flightTemplate.Rows(x).HeaderCell.Value = alphabet(x).ToString
Next
Me.Controls.Add(dgv_flightTemplate)
dgv_flightTemplate.Location = New Point(400, 400)
dgv_flightTemplate.AllowUserToAddRows = False
dgv_flightTemplate.AllowUserToDeleteRows = False
dgv_flightTemplate.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
dgv_flightTemplate.AutoResizeRows()
dgv_flightTemplate.AutoSize = True
End Sub
End Class
https://it.toolbox.com/question/event-for-dynamically-created-command-button-043008
Edit: Olivier Jacot-Descombes response was perfect all that was needed was run the "Init" sub.
Public Class seattemplatecreator
Dim alphabet() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()
Private WithEvents dgv_flightTemplate As DataGridView
'help from https://it.toolbox.com/question/event-for-dynamically-created-command-button-043008
Public Sub init(ByVal dgv01 As DataGridView)
dgv_flightTemplate = dgv01
End Sub
Private Sub dgv_flightTemplate_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv_flightTemplate.CellMouseDoubleClick
MsgBox("workwd")
End Sub
Private Sub btn_createflight_Click(sender As Object, e As EventArgs) Handles btn_createflight.Click
'used https://social.msdn.microsoft.com/Forums/vstudio/en-US/e222f438-f060-4e61-ab28-523d02db91b2/how-to-programmatically-create-datagridview-with-empty-columns-and-rows?forum=vbgeneral
'to help with this part for automatically generating the datagridview
MsgBox(alphabet(0))
Dim dgv_flightTemplate As New DataGridView
Dim c As Integer = txb_columns.Text
Dim r As Integer = txb_rows.Text
For colcount As Integer = 0 To c - 1
Dim nc As New DataGridViewTextBoxColumn
nc.Name = "Seating Column"
dgv_flightTemplate.Columns.Add(nc)
Next
dgv_flightTemplate.Rows.Add(r)
For x = 0 To r - 1
dgv_flightTemplate.Rows(x).HeaderCell.Value = alphabet(x).ToString
Next
Me.Controls.Add(dgv_flightTemplate)
dgv_flightTemplate.Location = New Point(400, 400)
dgv_flightTemplate.AllowUserToAddRows = False
dgv_flightTemplate.AllowUserToDeleteRows = False
dgv_flightTemplate.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
dgv_flightTemplate.AutoResizeRows()
dgv_flightTemplate.AutoSize = True
init(dgv_flightTemplate)
End Sub
End Class
Any help would be greatly appreciated
Thanks, Taine
You are not calling Init. But instead, you could as well directly assign to the field
dgv_flightTemplate = New DataGridView 'Note: No Dim here.
But even if you are creating the columns dynamically, you could add a grid with the designer. Just call
dgv_flightTemplate.Columns.Clear()
before adding columns.

Restricting SpinButtons to specific Min and Max values VBA

I am trying to restrict user to select value between a limit using SpinButton in VBA but its not working for me
Here is what I have tried
Private Sub UserForm_Initialize()
decimalSpin_Button.Min = 0
decimalSpin_Button.Max = 5
End Sub
Private Sub decimalSpin_Button_Change()
decimalPlaces_Value.Text = decimalSpin_Button.Value
End Sub
Private Sub decimalSpin_Button_SpinDown()
decimalPlaces_Value.Text = decimalPlaces_Value.Text - 1
End Sub
Private Sub decimalSpin_Button_SpinUp()
decimalPlaces_Value.Text = val(decimalPlaces_Value.Text) + 1
End Sub
You don't need the _SpinDown() and _SpinUp() This will do what you want
Private Sub UserForm_Initialize()
decimalSpin_Button.Min = 0
decimalSpin_Button.Max = 5
End Sub
Private Sub decimalSpin_Button_Change()
decimalPlaces_Value.Text = decimalSpin_Button.Value
End Sub

how to assign value to NodeLabelEditEventArgs variable

i created this sub
Sub CreateNewNode(tree As TreeView, e As NodeLabelEditEventArgs)
Dim nodeTxt As String
nodeTxt = e.Label
If e.Node.Level = 0 Then
Dim obj_carsType As New Cls_carsType
Dim Entity As New tblcarsType
Entity.Type = nodeTxt
obj_carsType .Insert(Entity)
Dim q = (From i In obj_logsType.Fill Select i.ID).Last
e.CancelEdit = True
tree.Nodes.Remove(e.Node)
tree.Nodes.Add(nodeTxt & " : " & q.tostring)
end sub
Sub TreeView1_NodeMouseClick()
e.Node.ContextMenuStrip =ContextMenuStrip1
end sub
Private Sub NEWITEmToolStripMenuItem_Click()
end sub
in last sub need to call first sub. also in last sub if user click on NEWITEM i must call the first sub how can i do it?? please help me
I think you need something like this:
Private Sub NEWITEmToolStripMenuItem_Click(byval sender as object, byval e as eventargs)
CreateNewNode(ctype(sender, TreeView), ctype(e,NodeLabelEditEventArgs))
end sub