|
I have an application that connects to a large Access database for its data. Strange thing: The program does unpredictable things (does not update the Access database or locks up) when accessing the database for the first time. This only happens the first time it is run right after it is installed. Any accessing to the database after the first time works without any problems. This can be reproduced on more than one computer. It never happens when running from the development environment. An ideas why this is happening?
|
|
|
|
|
can you give the code sample used for updating database and not updating first time.
IT IS NOT AS IMPORTANT AS WHETHER YOU SUCCEED OR FAIL BUT WHAT IMPORTANT IS THAT YOU TRY YOUR BEST.
SO ALWAYS TRY AT YOUR LEVEL BEST
|
|
|
|
|
Hello -
I am trying to make all textboxes, comboboxes, and datetimepickers on my form ReadOnly.
But only if certain criteria is True therefore, I need to do this at runtime.
Also, there are lots of controls on my form that need to be switched so I would love to be able to
make this switch to ReadOnly without having to explicitly nameing each contol
for example I don't want to have to write the following code for every control :
textbox1.readonly = TRUE
I would like to be able to use the control collection if possible.
For x = 0 To (Me.Controls.Count - 1)
Select Case Me.Controls(x).GetType.Name
Case "Textbox"
. . .
Case "Button"
. . .
Case "Label"
. . .
Case Else
Me.Controls(x).Enabled = False
End Select
Next x
Does anyone have any suggestions ?
Thank you for all replys
Shawn Owens
|
|
|
|
|
yes, I don't see any reason for this not to work, although I would use foreach to iterate over them. Does this code not work for you ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The main problem I have using this code is
accessing a controls ReadOnly property.
Intelisense does not recognize:
me.controls(x).name.readonly = True
it would be nice if there were an allTextboxes property for the form
or something like that.
|
|
|
|
|
Perhaps not all controls have a readonly property ? See if there's a base class or interface you can use to access this property, if not, you need to cast the objects to get to it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
How would I go about casting the objects ?
Do I use ctype() ? and do I cast them to type textbox (or
whatever control is appropriate) or type obj ?
Thank you so much
Shawn
|
|
|
|
|
Yes, if it's a textbox, cast it to a textbox. I guess ctype is what you need, not sure.
Or, look if an interface is used to impliment read only in controls, then you can cast all to that.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You'd use CType to cast the control instance to the type of control your working with. The "gotcha" in doing something like this is that controls can be parents of other controls, such as when a TextBox sits in a Panel, the TextBox won't show up in the Form's Controls collection. You'd have to use recursion to go through all the child controls of each control to find everything you need.
If you have a group of controls of different types that nbeed to be set as ReadOnyl, drop them all into a Panel or GroupBox control. That way, all you'd have to do is something like this:
Private Sub SetControlsReadOnlyState(ByRef rootContainer As Control, ByVal state As Boolean)
For Each c As Control In rootContainer.Controls
If TypeOf c Is TextBox Then
Dim tb As TextBox = CType(c, TextBox)
tb.ReadOnly = state
End If
If c.HasChildren Then
SetControlsReadOnlyState(c, state)
End If
Next
End Sub
Then to call this and set all the TextBox controls inside Panel1 to ReadOnly, all you'd have to do is:
SetControlsReadOnlyState(Panel1, True)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I love recursion !
This will do just fine,
Thanks Christian and Dave !
|
|
|
|
|
just a few things that i need to know,
How to create a MsgBox that allows me to load another form when i click yes and when i click no it closes program?
Also how do i do a global variable becauase i cant reset my 'rlmemory' sum back to 0 from another form or can I?
thats all
thanks in advance
|
|
|
|
|
Ultima Reborn wrote: How to create a MsgBox that allows me to load another form when i click yes and when i click no it closes program?
You need to not use MSgBox if you're using VB.NET. Use MessageBox.Show, which has a parameter to specify what buttons you show, and then you can check the DialogResult that is returned to decide which action to take.
Ultima Reborn wrote: Also how do i do a global variable becauase i cant reset my 'rlmemory' sum back to 0 from another form or can I?
You can't. Global variables are generally a bad idea. You can create what you want with a public shared variable, but I'd advise against it.
Ultima Reborn wrote: becauase i cant reset my 'rlmemory' sum back to 0 from another form or can I?
I have no idea what your rlmemory sum is, but I assume it's an int or something. You can use delegates for inter form communication. You can also make it shared, if there's only one within the app. Also, if your form that contains the value is a child of the form that wants to change it, you can do it directly.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You can use MsgBox. Try this:
<br />
MsgBox("Text here", MsgBoxStyle.YesNo)<br />
If DialogResult = Windows.Forms.DialogResult.Yes Then<br />
FormName.Show()<br />
Else<br />
Me.Close()<br />
End If<br />
|
|
|
|
|
Uhhh...what? Where is DialogResult going to get set?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Correction to my last post, a small code mistake. Try this instead:
<br />
MsgBox("Text Goes Here.", MsgBoxStyle.YesNo)<br />
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then<br />
FormName.Show()<br />
End If<br />
You do not need to have a IF statement for the "No" button.
|
|
|
|
|
This still won't work. Your comparing an Enum value to itself which will ALWAYS return TRUE!!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
ok thanks for the message box help
So how do i get the "no" button to do a different procedure?
for it i have
MsgBox("Message", MsgBoxStyle.YesNo)
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then
txtTotal.Text = CStr(rlMemory)
Form2.txtTotalCost.Text = CStr(rlMemory)
Form2.txtDiscount.Clear()
Form2.Show()
End If
for that variable thing i have
Dim intNights As Integer
Dim rlPrice As Single
Dim rlTotal As Single
Dim rlMemory As Single
basically rlMemory stores the data i need, but at the end of the program when u get a diaglog box giving you the option to restart the program, at this point i need the rlmemory to go back to 0.
-- modified at 16:40 Tuesday 17th October, 2006
|
|
|
|
|
Here is how you should do it:
<br />
Dim BoxCall As MsgBoxResult<br />
BoxCall = MsgBox("Message", MsgBoxStyle.YesNo)<br />
If BoxCall = MsgBoxResult.Yes Then<br />
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then<br />
txtTotal.Text = CStr(rlMemory)<br />
Form2.txtTotalCost.Text = CStr(rlMemory)<br />
Form2.txtDiscount.Clear()<br />
Form2.Show()<br />
Else<br />
'Code for "No" goes here. Leave blank if no procedure is needed.<br />
End If<br />
And you said that you want rlmemory to go to 0? If so, then use this:
rlmemory = "0" .
Hope this helps.
|
|
|
|
|
UltraCoder wrote: rlmemory = "0".
Assuming it is a string. I'd have assumed otherwise.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Have you noticed anything weird about the two if statements in the post you replied to?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
with the messagebox i have
Dim BoxCall As MsgBoxResult
BoxCall = MsgBox("Message", MsgBoxStyle.YesNo)
If BoxCall = MsgBoxResult.Yes Then
If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then
txtTotal.Text = CStr(rlMemory)
Form2.txtTotalCost.Text = CStr(rlMemory)
Form2.txtDiscount.Clear()
Form2.Show()
Else
Form4.txtTotalCost.Text = CStr(rlMemory)
Form4.Show()
End If
End If
but form 4 doesnt show =z
well i tried using rlmemory = "0" but it doesnt reconise it as its on another form also i did have it in the form load but didnt seem to work if i wanted to re add something
Example of what program does
(working in down structure)
Menu (form)
calculation (form) <--input data \ calculate it
total (form) <-- takes final sum and has it on a new form with do u want to do calculation again
-- modified at 21:00 Tuesday 17th October, 2006
|
|
|
|
|
Ok, for one, remove "If System.Windows.Forms.DialogResult.Yes = Windows.Forms.DialogResult.Yes Then" and then the duplicate "End IF" at the bottom, (A small mistake on my part).
For the "No", use the same procedure as "Yes". Example:
<br />
If BoxCall = MsgBoxResult.No Then<br />
'Code Goes Here<br />
End If<br />
And as for clearing the "rlmemory" varible, try rlmemory = 0 , or if the varible is in another form, you might have to use something like a setting to hold the varible..
I hope this helps. If not, you could try posting the code for "rlmemory" (setting/removing values etc.)
|
|
|
|
|
Ultra,
1) Ultra coder seemingly is testing the same enum against itself which is not giving you your answer. System library is implied that's why you do not have to use the 'import' key word in most cases.
If MsgBox("text goes here", MsgBoxStyle.Question + MsgBoxStyle.YesNo + _
MsgBoxStyle.DefaultButton2,"form title") = MsgBoxResult.Yes Then
Dim oFrm as new Form2
oFrm.ShowDialog
oFrm.Dispose
oFrm = Nothing
Else
Close()
End If
2) Instead of telling you that it's a bad idea. no one seemingly answered your question. "how do i do a global variable". You do this by creating module file (old bas extension) and adding a public variable in there. Because a module is considered public by all files in your project, the variable is available from every piece of code.
Module basMain
public gsValue as string '<--- global variable
End Module
'now you can update or ask for the value of the variable anywhere
class form1
private sub ShowMeValue
msgbox gsValue
end sub
end class
3) You asked if you can update a variable of one form from another. There are a lot of methods that are not the most desirable but saying that "you can't" is not correct. Were there's a will there's a way. One way is to pass the pointer of the form1 into form2 via a routine.
class form1
public msVariable as string
private sub CallAnotherForm
Dim oFrm as new form2
ofrm.ExecuteMethod(me) '<---
ofrm.showdialog
ofrm.dispose
ofrm = nothing
end sub
End Class
class form2
public sub ExecuteMethod(oFrm as form1)
oFrm.msVariable="Hello" 'you just updated the variable of form1
End Sub
end class
Hope this helps...
Nathan
|
|
|
|
|
I have tried this method and it does not work! The method I posted works fine!
|
|
|
|
|
It works because you only tested one case for your if statements. They ALWAYS return True because, in essence, you did this: If 2 = 2 Then ... .
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|