|
i'm not sure i usnderstand exactly what you mean - you need want to have a separate class that holds your data connection objects and reference that from a form?
|
|
|
|
|
Hi I am totally a new commer in VB or VB . Net i m trying to make a simple windows application. that has two textboxes in it. i want to make my own student class with two members Name and gpa. and two methods one to assign the values to the variables and the 2nd one to show them in the textboxes. and i want to access this class in another class by creating its object in it. i am having following problems.
i) textboxes r not accessible in my student class.
ii)when i added these variables and function in the Form1 class (for the textboxes to b accessible) and created the object of Form1 in my own class i was unable to access the variables and methods of Form1 class.
I am giving the code as well.
Public Class Form1
Inherits System.Windows.Forms.Form
Private name As String
Private gpa As Double
Public Function assignvalue()
name = InputBox("Enter the name of students")
gpa = InputBox("Enter the name of studentsFather")
End Function
Public Function showvalue()
textbox1.Text() = name
textbox2.Text() = gpa
End Function
Public Class MyClass
Dim s1 As New Form1
s1.assignvalue()
s1.showvalue()
End Class
End Class
now when i run this program it gives error on s1.assignvalue() and s1.showvalue()
D:\VB Projects\WindowsApplication1\Form1.vb(168): Declaration expected.
somebody plzz help me out
looking forward for help
Regards,
|
|
|
|
|
Well It would be good to get a better answer than this. Its a kind of scope problem and it seems naming a class myClass is not liked and similar conflict naming a variable name, they are keywords.
So I changed it a little bit
Public Class Form1
Inherits System.Windows.Forms.Form
Dim t1 As TextBox
Dim t2 As TextBox
Private name1 As String
Private gpa As Double
Public Function assignvalue()
name1 = InputBox("Enter the name of students")
gpa = InputBox("Enter the GPA")
showvalue()
End Function
Public Function showvalue()
TextBox1.Text() = name1
t1.Text() = gpa
End Function
Public Class displayme
Public Shared Function show()
Dim s1 As New Form1
s1.assignvalue()
s1.showvalue()
s1.Show()
Dim t1 = New TextBox
Dim t2 = New TextBox
s1.Controls.AddRange(New Control() {t1, t2})
t1.Location = New Point(20, 50)
t2.Location = New Point(20, 100)
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
displayme.show()
End Sub
End Class
|
|
|
|
|
Thxx Sir, but it isnt working eithr it is giving hell lot of errors
|
|
|
|
|
Sorry,
I think i made it worse. I will look at it, im just learning so it is interesting. Especially the scope part of it. Maybe try separating the classes a bit more, instead of having one inside another. But I am sure we will sort this out.
But it works if you keep your class outside the other class. I don't think nested classes are going to work!
Public Class Form1
Inherits System.Windows.Forms.Form
+windows Generated Code-----------
----------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New aClass
Label1.Text = f.myfunction
Label1.Text = f.showName
End Sub
End Class
Public Class aClass
Private strName As String
Private gpa As Double
Public Function myfunction()
strName = InputBox("Enter the name of students")
End Function
Public Function showName()
Return strName
End Function
End Class
|
|
|
|
|
Can someone give me the code for pins changed event of serialort in vb?
|
|
|
|
|
How do you go about making your class accessible to other projects ?
Like say you have a custom messagebox ?
-- modified at 21:30 Friday 7th July, 2006
|
|
|
|
|
Put it in a DLL.
Best,
Jun
|
|
|
|
|
Sorry about this question but how do you make the dll ?
|
|
|
|
|
had inserted datetime values in databse field like '" + DateTime.now + "'
now i want to comapre valus using betwwen operator of SQL
i.e where dbtime between '" + dtp1.value + "' AND '" + dtp2.value + "' but it does not show any record i think critera of where class did not match.
how to compare them so that it show correct result
Tasleem Arif
|
|
|
|
|
Can you paste your code here? might be easy to help you that way.
Difficult - > Challenging, this simple replacement made me take my life little easy;)
|
|
|
|
|
str="INSERT INTO tblHistoryLog(UserId,UserAction,TableName,ActionDate,TrDoneOn) VALUES('" + CheckValues.strUserId + "','NEW RECORD','USER TABLE','" + DateTime.Now + "','" + cmbTAUserId.Text + "')";
where ActionDate datatype if datetime.
i had inserted record in the table and inserted properly.
the query that uses the comparison
"SELECT * FROM tblHistoryLog WHERE (ActionDate BETWEEN #"+ dtpTo.Value +"# AND #"+ dtpFrom.Value +"#)"
but it gives the no result
i had tried to use this but it does not compile so i had to use above
"+ #dtpTo.Value# +" AND "+ #dtpFrom.Value# +"
Tasleem Arif
|
|
|
|
|
What database are you using?
What is the data type of the field in the database?
---
b { font-weight: normal; }
-- modified at 8:07 Saturday 8th July, 2006
|
|
|
|
|
datatype is datetime and i m using sql server2000
Tasleem Arif
|
|
|
|
|
Then you shouldn't use # arounds the date values. That is use with MS Access.
---
b { font-weight: normal; }
|
|
|
|
|
I assume that you are using either ASP.NET or windows forms as client. Try following:
"ActionDate BETWEEN" & " '" & Convert.ToDateTime(dtpFrom.Value).ToLongDateString & "' AND " & " '" & Convert.ToDateTime(dtpTo.Text).ToLongDateString & "'"
I also notice in your code, you are going from To...From! usually it is From...To right?
Hope this helps.
Difficult - > Challenging, this simple replacement made me take my life little easy;)
|
|
|
|
|
Hi everybody,
I use the following code to download a file from the Inet:
<br />
Private myClient As WebClient<br />
<br />
Private sub Load_It<br />
<br />
MyClient = New WebClient()<br />
MyClient.DownloadFile(myURIStr, fileName)<br />
<br />
End sub
This takes about 30 to 35 secs to fail if it cannot stablish a connection. Since I wanted to be able to Cancel the download at will, I tried calling this method from a running thread; but after this, I get an inmediate connection error when I try to download the file again; which does not happend if a wait for it to fail when using it outside the thread.
Any helpful ideas?
thanks.
The same lost guy
-- modified at 10:01 Saturday 8th July, 2006
|
|
|
|
|
Hi everyone.
I have developed a crystal report of "Books" table and when I view it in crytal report viewer, it ask me about the server name, database name, user name and password.
Although the other default samples of Crytal Reports are running well... there is no any constraint of username and password in database and getting it easily in my .net application but having problem in crystal reports.
Kindly reply me. It is urgent.
Thank You
Syed Ali Raza Rizvi
|
|
|
|
|
i had the same problem, this is basically how i solved it.
use this code to generate your report -
<br />
Private Function SetDataSource _ <br />
(ByVal conn As String, ByVal query As String, _<br />
ByVal dataSet As DataSet)<br />
<br />
' create a new connection & data adapter object <br />
Dim oleConn As New OleDbConnection(conn)<br />
Dim oleAdapter As New OleDbDataAdapter()<br />
'pass your query to the data adapter<br />
oleAdapter.SelectCommand = New OleDbCommand(query, oleConn)<br />
<br />
' Connect to the data source, fetch the data, and disconnect <br />
' from the database.<br />
Try<br />
oleAdapter.Fill(dataSet, "Books")<br />
Catch ex as Exception<br />
Messagebox.Show(ex.InnerException.ToString)<br />
End Try<br />
<br />
' Pass the populated data set to the report.<br />
Report.SetDataSource(dataSet)<br />
<br />
' Set the report viewer to show the report (if you have<br />
' multiple reports for the same viewer and haven't set<br />
' the ReportSource property of the viewer)<br />
Form1.CrystalReportViewer1.ReportSource = Report<br />
<br />
End Function<br />
<br />
|
|
|
|
|
I am using this code to change text color of listview selected item. But it never works.Could an expert look at it and tell me what i am doing wrong. The hwnd is corect since the line :
[code=vb]lItemPos = 0& ' first item
SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM[/code]
is working perfectly and is selecing the zero position item for me and highlighting it corectly.
Some people suggest i need to send a refresh using LVM_REDRAWITEMS to listview after setting a color for it. But i do not know how to use LVM_REDRAWITEMS. I be happy if an expert help me fix there problems.Thanks
not working call to LVM_SETITEMSTATE
Private Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38) <br />
<br />
lItemPos = 0& ' first item<br />
SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM<br />
<br />
'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, hexdec(16711935)<br />
'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, 16711935<br />
'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0&, 0&<br />
<br />
<br />
<br />
SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, 16711935<br />
<br />
-- modified at 12:20 Friday 7th July, 2006
|
|
|
|
|
Are you doing this so you can change that appearance of a listview in your own app or another one?? If your doing this in your own ass, you're going about it the hard way. search the articles for "ownerdraw listview" and you'll come up with a few good examples.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am doing this for external listview . I mean in another application that i do not have its source code!
|
|
|
|
|
OK. Well, the docs on the LVM_REDRAWITEMS[^] message are pretty straight forward. You already have the mechanism to send the message. All you need to do is supply the listviews first and last item numbers that need to be redrawn.
Now, you have a second, more serious problem, that you can't get around. If this was your own ListView and your were ownerdrawing it, your code would have to be written to specifically handle this message. I have yet to see an ownerdrawn ListView that does this. If the app your trying to control like this ownerdraws its ListView control, you're S.O.L, and none of this will ever matter.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
could u tell me what should i put for the parameters in my case :
SendMessage(
(HWND) hWndControl,
(UINT) LVM_SETTEXTCOLOR,
(WPARAM) wParam,
(LPARAM) lParam
<br />
);
I have no idea what should put and replace what ?
|
|
|
|
|
Don't tell me you copy-paste-and-prayed the code you posted??
LVM_REDRAWITEMS is (LVM_FIRST + 21)
The wParam value should be the index number of the first ListView item that needs to be redrawn. The lParam value should be the index of the last item.
So, you're code would be something like:
Private Const LVM_REDRAWITEMS = (LVM_FIRST + 21)
.
.
.
SendMessage hwnd, LVM_REDRAWITEMS, firstItemIndex, lastItemIndex
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|