|
Windows Forms are not thread safe, since you want to update the textbox from another thread you will need to marshal the update method to the original thread (the main form thread) and execute the method there.
Code might look like this:
Delegate Sub TextDelegate(ByVal Text As String) 'Declared Somewhere
Sub SetText(ByVal Text As String) 'Declared Somewhere
Me.TextBox1.Text = Text
End Sub
'From second thread
If TextBox1.InvokeRequired Then TextBox1.Invoke(New TextDelegate(AddressOf SetText), "Hello")
'If calling from a second thread, create a bridge (Delegate) to a custom sub on the fly and tell the first thread to execute it through the safe bridge
Hope this clarifies something
|
|
|
|
|
Thanks, that's helpful... but....
Textbox1.invokeRequired returns false and yet
textbox1.text = "Hello"
still doesn't write to the textbox.
How can that be?
|
|
|
|
|
Would you mind posting a small code snippet, please?
|
|
|
|
|
HI Yone!
Thanks for your help. I'm still puzzled. Here is the thing..
The test buttonpress routine below calls the backgroundworker which then prints to the textbox using the delegate. This works fine.
However, the same call from the application sub does not invoke the delegate!
'THIS IS THE SUB THAT CALLS THE WRITETOLOG FUNCTION FROM ANOTHER CLASS
Public Class Application
Public Sub onLogon()
Implements QuickFix.Application.onLogon
Form1.WriteToLog("Logon Successful")
End Sub
End class
'THIS IS THE CLASS THAT HAS THE TEXTBOX
Public Class Form1
Public Function WriteToLog(ByVal Whattowrite)
'THIS WORKS FINE IF CALLED FROM BUTTONPRESS BELOW
'THIS IS IGNORED IF CALLED FROM APPLICATION CLASS SUB ABOVE
If TextBox1.InvokeRequired Then
TextBox1.Invoke(New TextDelegate(AddressOf SetText), _
TextBox1.Text & Whattowrite & vbCrLf)
End If
If Not TextBox1.InvokeRequired Then
TextBox1.Text = TextBox1.Text & "Not" & Whattowrite &
vbCrLf
End If
End Function
Sub SetText(ByVal Text As String) 'Declared Somewhere
TextBox1.Text = Text
End Sub
Delegate Sub TextDelegate(ByVal Text As String) 'Declared Somewhere
'BELOW IS ROUTINE TO TEST THE WRITETOLOG FUNCTION FROM A
BACKGROUND THREAD (WORKS FINE)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As _
System.Object, ByVal e As _
System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
WriteToLog("From BWorker")
End Sub
|
|
|
|
|
When your calling the sub onLogon() it calls the WriteToLog() method on another Form1 Class, (its just a class as any other class) You need to somehow pass a reference to the original Form1 class that was created when your application started to the Application Class, and call WriteToLog() on that reference.
Code might look like this:
'Class Declaration
<br />
Public Class Application<br />
Public frm As Form1 = Nothing<br />
<br />
Public Sub onLogon()<br />
If frm IsNot Nothing Then frm.WriteToLog("Hello from Application class")<br />
End Sub<br />
End Class<br />
'From any sub or other thread:
<br />
Dim a as New Application<br />
a.frm = me<br />
a.onLogon<br />
I tested it and it worked in my test setup
|
|
|
|
|
I'm using Crystal Reports in my vb.net project, for some reason this version of Crystal Reports is designed to disable mouse scroll or keyboard scroll. Is there any way I can enable the scroll by writing some code, because the only other way to enable the scroll is to do an upgrade.
Thanks,
Zee
|
|
|
|
|
Dim ParamSeparator() As String = {"GIF89a"}<br />
Dim gif As String = File.ReadAllText(OpenFileDialog1.FileName)<br />
For Each files As String In gif.Split(ParamSeparator, StringSplitOptions.None)<br />
<br />
Next
I wrote this code but it didn't work with Binary Files, so i want to know how to edit it for make working with Binary FIles.
Thanx for any help
|
|
|
|
|
Why did you do this when I told you what to do the last time you asked this question ?
Christian Graus - C++ MVP
|
|
|
|
|
Hello
I am makeing a quiz application and I am haveing problem with randomize
In multiple section I put 4 options and 3 is wrong answers and 1 is right answer so i randomize the questions but i also want to randomize the answers in lebels boxes so any help how to ransomize the answers
i used arrays for example how i create quiz
qus(0)="This the question ?" : ans1(0)="A" : ans2(0)="B" : ans3(0)="C" : ans4(0)="D"
thet's how i create array to display questions and it's options
and i put 4 buttons and 4 labels in front of it
and answers display in labels
lblA.txt = ans1(I)
lblB.txt = ans2(I)
lblC.txt = ans3(I)
lblD.txt = ans4(I)
any help please
|
|
|
|
|
Random.Next is how you get random numbers.
Christian Graus - C++ MVP
|
|
|
|
|
Hello
First of all thank you very much for your kind rep
I have allready done randomuzation for this quiz and it's working ok but i also want to randomize possible answers in label box at this time it's all comeing in same place every time like lblA = a , lblB = b , lblC = c , lblD = d , but i want to randomize the 4 possible answers in label box i dont want answer "a" in lblA every time
please have a look my first post
wating for your kind rep.
have a nice time
|
|
|
|
|
So, you need to shuffle the four answers. One way to do this is to build an array of answers, and grab them out of htere at random, to fill the four spots.
Christian Graus - C++ MVP
|
|
|
|
|
Hello
Thank you very much for quick rep.
this is my question and answer array
'get questions and answers arrays
Question(0) = "Macadamia and almonnd are types of what ?" : Ans1(0) = "Nuts" : Ans2(0) = "Fruit" : Ans3(0) = "Tree" : Ans4(0) = "Vagetable" : Clue(0) = "Do you know about any magazine ?" : CorrectAns(0) = "Nuts"
Question(1) = "In astrology the star sign Piseces is represented by which animal ?" : Ans1(1) = "Donkey" : Ans2(1) = "Fish" : Ans3(1) = "Lion" : Ans4(1) = "Snake" : Clue(1) = "It,s very testy" : CorrectAns(1) = "Fish"
Question(2) = "Where is Tower bridge ?" : Ans1(2) = "USA" : Ans2(2) = "Dubai" : Ans3(2) = "London" : Ans4(2) = "India" : Clue(2) = "Sterling" : CorrectAns(2) = "London"
Question(3) = "Where is liberty statue ?" : Ans1(3) = "India" : Ans2(3) = "London" : Ans3(3) = "Dubai" : Ans4(3) = "USA" : Clue(3) = "NY" : CorrectAns(3) = "USA"
Question(4) = "In geography where is Mount Fuji ?" : Ans1(4) = "Japan" : Ans2(4) = "Taiwan" : Ans3(4) = "China" : Ans4(4) = "USA" : Clue(4) = "It's very small country " : CorrectAns(4) = "Japan"
but i tryed lot but still i am strugling
wating for your kind rep.
have a nice time
thank you
|
|
|
|
|
Well, sure it is. Did you try what I suggested ?
Anyhow, your structure sucks. Ans1 and Ans2 are different arrays ? You have an array of answers for the first spot, but the four answers that go with a question do not relate to each other ? You should have one array of a struct, with the four answers, and the correct one.
Then you get an array of four numbers, 0 to 3. You get a random number between 0 and 3, and you grab the index in this array of that number. That's the index for position one. You remove that number from the number array, get a random number between 0 and 2. Get hte number at that index. That's the index to show next. Etc.
Christian Graus - C++ MVP
|
|
|
|
|
Hello Sir
thank you very very much
I got it
and thank you very much for your very quick rep.
thanks again for this
byyyyyyyy
|
|
|
|
|
I am trying to populate a datagrid using a SQL select statement. The statement contains a "WHERE fieldname LIKE textbox.text" as below in my code. The problem is, I can't get the code right to display the data in the grid when the button is clicked. Here is my code so far:
Public Sub loadDoc()
Dim DAdapt As SqlDataAdapter
Dim custMap As DataTableMapping = DAdapt.TableMappings.Add("Table", "DocumentList")
custMap.ColumnMappings.Add("Title", "Title")
custMap.ColumnMappings.Add("Expiration", "Expiration")
custMap.ColumnMappings.Add("Keywords", "Keywords")
Dim sql2 As String = "Select * FROM DocumentList WHERE Keywords LIKE '" & tbSearch.Text & "'"
Dim ds As New DataSet
DAdapt = New SqlDataAdapter(sql2, cnn1)
Me.cnn1.Open()
DAdapt.Fill(ds)
Try
grdDocumentList.DataSource = ds.DefaultViewManager
ds.Clear()
ds.Merge(ds)
grdDocumentList.SetDataBinding(ds, "DocumentList")
Catch eLoadMerge As System.Exception
Throw eLoadMerge
End Try
Me.cnn1.Close()
End Sub
Thank you,
LWhite
|
|
|
|
|
Hmmm, I have never done it like that, try something like this
Dim DAdapt as new SqlDataAdapter
DAdaPt.SelectCommand = new SqlCommand
DAdapt.SelectCommand.CommandType = CommandType.Text
DAdapt.SelectCommand.Connection = cnn1
DAdapt.SelectCommand.CommandText = "Select * FROM DocumentList WHERE Keywords LIKE '" & search.Text & "'"
Dim ds as new Datatable("Display")
try
DAdapt.fill(ds)
Catch ex as SQLException
end try
grdDocumentList.Datasource = ds
|
|
|
|
|
Sweet! Thank you very much, that worked. I appreciate the assistance.
LWhite
|
|
|
|
|
I added another variation to this code that works very nicely to provide a search based on part of the "Keywords" field. Add this to the btnLoad_Click sub:
tbSearch.Text = "%" & tbSearch.Text & "%"
Again, Thanks to Kevin for the assist! Got the creative juices flowing again, lol.
LWhite
|
|
|
|
|
I am trying to copy a file from a web folder
("http://server/folder/file.ext") to a regular folder from my com+ component.
I was using an ADODB.Record with the msdaipp oledb provider. This works fine
in a desktop application but when I moved the code to my component - it
turns out this provider (because it uses wininet) cannot be used in a middle
tier or server side application. I am getting the error message "cannot find
the provider ...". The regular desktop app works fine on the same machine.
Do I have any other alternative? What other technique can I use to copy a file located on a web folder using my Com+ component and VB?
Thanks!
|
|
|
|
|
I am having a problem with accessing a web service and am hoping that someone out there can help me out...
I am working on a VB windows forms application that will access a web service running on a Windows 2003 server. As I am starting a new project, I decided that it's a good time to move from Visual Studio 2003 to Visual Studio 2005. My problem is that with VS2005 I can not access the web service and with VS2003 I can. Additionally, if I turn of my web proxy (Control Panel, Internet Options, Connections, LAN Settings) the web service works fine with VS2005. Unfortunately, turning off the proxy server is not an option. The error I get running VS2005 with the proxy server is "The request failed with HTTP status 403: Forbidden."
This is a sample of the code I'm working with:
Dim FAMISService As New FAMIS6.ImportEntity
Dim dtFAMISLocations As DataTable
FAMISService.PreAuthenticate = True
FAMISService.Credentials = System.Net.CredentialCache.DefaultCredentials
FAMISService.Proxy = System.Net.WebRequest.DefaultWebProxy
FAMISService.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
dtFAMISLocations = FAMISService.GetLocations().Tables(0)
I've tried it with and without the service proxy settings with no effect. Any thoughts or suggestions would be appreciated.
Regards,
TJS
|
|
|
|
|
After visual studio application is created, I copied all the files to another machine because I want to run it on another machine.
1. Does the local machine need to have SQL server installed in order to run the application?
2. Since Visual Studio application uses the SQL server path for connectionstring of development machine, How can I change the path on local machine to run the application?
3. Do I need to copy SQL Server database to local machine?
Any help would be appriciated.
Thank you in advance.
programmer
|
|
|
|
|
There should be no need to install SQL Server on the machine that the application is going to be run from. If you built the connection string on the development machine by dragging a connection from the server explorer into the development area, this string should work on any machine. This assumes that you aren't using windows authentication to connect to the server. (If thats the case make sure the user using the app has correct authentication to SQL Server on the data server). IF all that was done and the users machine is in the same network architecture as your development machine. It should work without problem.
-- modified at 13:33 Wednesday 15th November, 2006
|
|
|
|
|
I am a student in a colege, one of my projects involes making a program and learning about Visual Studio.
Getting Straight To the Point, I have looked on the internet at various dlls for zipping and compressing with a password ect, but i can't find a website that tells me how to include the dlls so that i can use them.
it would be greatley apreicated if someone could give me example code of a program that zips a file and unzips a file....
Most of the ones i have found have been For Vb6.
I can't seem to use this code, and don't know enough to convert it.
Please only answer with Visual Basic Code...... 2005 Edition
Thanks For Any Help, i have spent two days googling and now i think my head will explode.....thanks for any help.
Learning, For The Next Generation.......
|
|
|
|
|
have you looked at gzipstream ? it can do what you want...
|
|
|
|