|
just a thought..dont u hav to use inheritance to do this sorta thing?...I'm actully looking to do same thing as well but with no luk so far..
rubdub
|
|
|
|
|
Here it is -
Some background info for you that was given to me in the C# area
[Google on "Mediator pattern" and "MVC" (or "Model-View-Controller"). If you learn how to use these patterns, you'll never get stuck like this again; your code won't need tricks like passing a form to another form. I recommend "Design Patterns" by the Gang of Four.]
I just went to Microsoft ans sought out "Model-View-Controller"
As for the code. A no brainer once you do it, Key words "once you do it"
Once you have placed this very generic code in the forms and "Shared" class, go to project properties and
set the startup object to "Global" - this is you shared class, you can use this class or whatgever class you use for application prep, tracings and logs.
Option Strict On
Option Explicit On
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Global.postF2()
End Sub
End Class
Option Strict On
Option Explicit On
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Global.postF1(TextBox1.Text)
End Sub
End Class
Option Strict On
Option Explicit On
Public Class Global
Public Shared f1 As Form1
Public Shared f2 As Form2
Public Shared Sub main()
f1 = New Form1
Application.Run(f1)
End Sub
Public Shared Function postF2() As String
f2 = New Form2
f2.Show()
End Function
Public Shared Function postF1(ByVal post As String) As String
f1.Label1.Text = post
End Function
|
|
|
|
|
create a fillschema a dataset
I create a SYBASECOMMANDBUILDER (from DDTEK Sybase Driver)
I create a row from the dataset
I fill the row with data
I add the row back to the datatable
[rowstate is now UNCHANGED]
I make a change to the newly added row
[rowstate is still UNCHANGED]
Of course the following update command returns zero, since there are no rows that do not have a status of "UNCHANGED". Can someone explain to me what I did wrong? datarow adds and changes should change the rowstate to Added and Modified respectively. Thanks in advance
Have a blessed day in Messiah EYAWHOOSHUA!
|
|
|
|
|
I dont know how to do that. Directly in the Keypress event. Someone can help me ?
I am a newbie
|
|
|
|
|
Your definition of what you need is lacking. However, if I understand correctly, in a KeyPress event, you want to take the key that was pressed and convert it to uppercase. If this is your goal, try this in your sub
<br />
Dim key As Char = UCase(e.KeyChar)<br />
Hope this helps
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
TextBox1.CharacterCasing = CharacterCasing.Upper
That's what I neeeded
I am a newbie
|
|
|
|
|
i need a function, method, or api with which you can send a form to botton, not to top, so that the form will appear behind all other windows and above the desktop
thank you in advance
|
|
|
|
|
Hi,
From VB you can use ZOrder,
MyForm.ZOrder 0 will send the form to the top of the z order
MyForm.ZOrder 1 will send it to the bottom of the z order
If you are looking for more control, check SetWindowPos API function,
BOOL SetWindowPos(
HWND hWnd,
HWND hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
UINT uFlags
);
where hWndInsertAfter is a handle to the window to precede the positioned window in the Z order or one of the following values.
HWND_BOTTOM
HWND_NOTOPMOST
HWND_TOP
HWND_TOPMOST
Check the MSDN for a detailed explanation.
Fabian
|
|
|
|
|
Hello,
I am new to VB.NET and i need to accomplish this task. I have a form that contains a radiobuttonlist.
<tr>
<td class="NavyBold">Choose a Category:</td>
<td><asp:checkboxlist id="chkcomm" Runat="server" RepeatDirection="Vertical" RepeatColumns="2" AutoPostBack="false">
<asp:ListItem Value="Europe"></asp:ListItem>
<asp:ListItem Value="Australia"></asp:ListItem>
<asp:ListItem Value="North America"></asp:ListItem>
<asp:ListItem Value="Central America"></asp:ListItem>
<asp:ListItem Value="South America"></asp:ListItem>
<asp:ListItem Value="Asia"></asp:ListItem>
</asp:checkboxlist></td>
</tr>
Base on the selection on this radiobutton list once the form is submitted I have to generate an email to the department that can answer questions base on the category they chose on my radiobuttonlist.
How can I code this so I can accomplish this task. All the help will be appreciated.
|
|
|
|
|
Hi there. Well, in your code you're using a CheckBoxList object... do you want a RadioButtonList instead? If you have a single selected value (as in a RadioButtonList ) you could use the following code to get it:
Dim sValue as String = chkcomm.SelectedValue Or for multiple selections (as in a CheckBoxList ) you could enumerate through the items to see which are selected with code like this:
Dim i as Integer
For i = 0 to chkcomm.Items.Count - 1
If chkcomm.Items(i).Selected Then
'... do something with the selected item...
End If
Next To send the email, investigate the System.Web.Mail namespace. Here's a simple example:
Imports System.Web.Mail
Sub SendAMessage(sSendTo as string, sSubject as string, sBody as string)
Dim mm as MailMessage = new MailMessage()
'--set message properties
mm.From = "me@mycompany.com"
mm.To = sSendTo
mm.Subject = sSubject
mm.Body = sBody
'--set the SMTP server that will handle the outgoing message
SmtpMail.SmtpServer = "mycompany.com"
'--send the message
SmtpMail.Send(mm)
End Sub In your case, you would probably use a Select Case...End Select block to set up the .To property, based on the selected values. If you want more examples just do a search on CodeProject.
|
|
|
|
|
Hi thanks for the help.
Am I in the right direction with this. Base on the value selected on my radio button list i need to send an email to the the corresponding person pertaining to the subject.
thank in advance for the feedback.
Dim sValue as String = chkcomm.SelectedValue
Dim i as IntegerFor i = 0 to chkcomm.Items.Count - 1
If chkcomm.Items(i).Selected = 'Europe'
Then
'Sub SendAMessage(sSendTo as string, sSubject as string, sBody as string)
Sub Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Subject = "Europe"
Message.Body = "There is a new Europe Form that was submitted.Please click on the following link http://test/testfolder/continets/Main.aspx"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
'Catch error here
End Try
'End Sub
Else
chkcomm.Items(i).Selected = 'Australia'
Then
Sub Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Subject = "Australia"
Message.Body = "There is a new Autralia Form that was submitted.Please click on the following link http://test/testfolder/continets/Main.aspx"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
'Catch error here
End Try
Else
chkcomm.Items(i).Selected = Noth America'
Then
Sub Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Subject = "North America"
Message.Body = "There is a new Norht America Form that was submitted.Please click on the following link http://test/testfolder/continets/Main.aspx"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
'Catch error here
End Try
Else
chkcomm.Items(i).Selected = Central America'
Then
Sub Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Subject = "Central America"
Message.Body = "There is a new Central America Form that was submitted.Please click on the following link http://test/testfolder/continets/Main.aspx"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
'Catch error here
End Try
Else
chkcomm.Items(i).Selected = South America'
Then
Sub Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Subject = "South America"
Message.Body = "There is a new South America Form that was submitted.Please click on the following link http://test/testfolder/continets/Main.aspx"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
'Catch error here
End Try
Else
chkcomm.Items(i).Selected = Asia'
Then
Sub Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Subject = "Europe"
Message.Body = "There is a new Europe Form that was submitted.Please click on the following link http://test/testfolder/continets/Main.aspx"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ehttp As System.Web.HttpException
'Catch error here
End Try
End If
Next
|
|
|
|
|
Hi there. I'm guessing you are new to VB.NET? maybe new to programming? Generally I'd say you're on the right track, but you would certainly make your life easier to create a sub or function with parameters for sending the message. It looks like (for the moment) that the only properties changing for the message are the subject and body, and those are constructed from boiler-plate strings with the location. So, you could create your sub for sending the message with the location as a parameter:
Public Sub SendAMessage(sLocation as string)
dim Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
Message.To = "me@test.net"
Message.Cc = "you@test.net"
Message.Bcc = "us@test.net"
'--set subject and body depending on the location
Message.Subject = sLocation
Message.Body = string.Format( _
"There is a new {0} Form that was submitted. " & _
"Please click on the following link: " & _
"http://test/testfolder/continents/Main.aspx", _
sLocation)
Try
SmtpMail.SmtpServer = "TESTIMC01.TEST.com"
SmtpMail.Send(Message)
Catch ex As Exception
'do something with the error...
'... also, make sure to look at the
'... InnerException property; in the case
'... of mail exceptions, often InnerException
'... will give some better information of
'... what is going wrong
dim innerEx as Exception = ex.InnerException
if not (innerEx is nothing) then
'--inspect the innerEx message...
'-- perhaps write out to the log
end if
End Try
End Sub Then in your main sub you would inspect your RadioButtonList for its value and call the SendAMessage() sub with the proper location as a parameter. Again, assuming you have a RadioButtonList and not a CheckBoxList , then SelectedValue should work fine.
Public Sub InspectLocationAndSend()
'--get the value of the selected radio button
'-- this assumes the value is the desired location, like 'Europe'.
dim sLocation as string = myRadioButtonList.SelectedValue
'--Now call the sub that actually constructs and sends the message,
' based on the location
SendAMessage(sLocation)
End Sub What book(s) are you using to learn VB.NET and ASP.NET?
|
|
|
|
|
Thank you for the help...I know ill get there.
I wrote the long code because indeed when one of the items on my checkboxlist is selected the email has to go to a different person ie.
if europe is selected then send email to test@test.com if North America is selected then test2@test.com gets that email and so on.
I am fairly new (well realllllly new to .net) so I appreciate the help.
|
|
|
|
|
Okay - you'll want a Select Case block then. You could, for example, modify the SendAMessage sub to inspect the location and set the .To message property accordingly:
Public Sub SendAMessage(sLocation as string)
dim Message As MailMessage = New MailMessage
Message.From = "postmaster@test.net"
'--set the .To property depending on the location
Select Case sLocation.ToUpper()
Case "NORTH AMERICA": Message.To = "naRecipient@test.net"
Case "EUROPE" : Message.To = "europeRec@test.net"
'... other cases ...
Case Else : Message.To = "defaultRec@test.net"
End Select
'... other code as before ...
End Sub
|
|
|
|
|
I have a two form project. Form1 has one button on it with two lines of code:
Dim f_form2 As New Form2
f_form2.ShowDialog()
Form2 reads in a .JPG from SQL Server and displays the .JPG in a picture box on Form2. All this works great UNTIL I close Form2 and call it a second time. Form2 blows up with the following message:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file "C:\pic.jpg" because it is being used by another process.
If I close down the whole app and restart it, it's fine until the second call to Form2, so I'm obviously not releasing something correctly but don't know what to try. Help!
Thanks in advance.
*** here's the code ****
<br />
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
Dim fs As New FileStream("C:\pic.jpg", FileMode.Create, FileAccess.Write) 'blows up here second time form is called<br />
Dim bw As New BinaryWriter(fs)<br />
<br />
Dim Buffersize As Integer = 16384<br />
Dim Outbyte(Buffersize - 1) As Byte<br />
Dim retval As Long<br />
Dim startindex As Long = 0<br />
Dim actualsize As Integer<br />
<br />
Dim ConString As String<br />
ConString = ("Persist Security Info=False;Integrated Security=SSPI;Data Source=(local);Database=db")<br />
<br />
Dim strSQLCommand As String<br />
strSQLCommand = "select blob_segment from blob where picid = 574739053"<br />
<br />
Dim Connection As New SqlConnection(ConString)<br />
<br />
Dim Command As New SqlCommand(strSQLCommand, Connection)<br />
<br />
Connection.Open()<br />
Dim Reader As SqlDataReader = Command.ExecuteReader(CommandBehavior.SequentialAccess)<br />
<br />
actualsize = 0<br />
<br />
Do While Reader.Read<br />
startindex = 0<br />
<br />
retval = Reader.GetBytes(0, startindex, Outbyte, 0, Buffersize)<br />
<br />
Do While retval = Buffersize<br />
MsgBox(Str(Buffersize))<br />
bw.Write(Outbyte)<br />
bw.Flush()<br />
startindex += Buffersize<br />
retval = Reader.GetBytes(0, startindex, Outbyte, 0, Buffersize)<br />
Loop<br />
<br />
bw.Write(Outbyte, 0, CInt(retval))<br />
bw.Flush()<br />
fs.Flush()<br />
bw.Close()<br />
fs.Close()<br />
<br />
Loop<br />
<br />
Reader.Close()<br />
Connection.Close()<br />
<br />
PictureBox1.Image = Image.FromFile("c:\pic.jpg")<br />
<br />
End Sub
|
|
|
|
|
VB is not my thing, but it looks like your file isn't being closed correctly.
Try moving these lines:
bw.Flush()
fs.Flush()
bw.Close()
fs.Close()
outside the loop.
I don't quite know what your code is supposed to do, but I'm not sure if there are other errors because I'm not really that familiar with VB, but the opening of those objects is not occuring inside the loop, so the closing typically shouldn't be done inside the loop either.
And actually, you can drop all those calls except bw.close(). Calling bw.Close() will automatically flush and close the underlying stream.
|
|
|
|
|
Thanks for your reply.
I played with this a bit this weekend, it seems to be a rights issue. The following code blows up with the same error.
"Additional information: The process cannot access the file "c:\mypic.jpg" because it is being used by another process."
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
File.Copy("c:\blue.jpg", "c:\mypic.jpg", True)<br />
<br />
PictureBox1.Image = Image.FromFile("c:\mypic.jpg")<br />
<br />
PictureBox1.Refresh()<br />
<br />
File.Copy("c:\green.jpg", "c:\mypic.jpg", True) <<< blows up here <br />
<br />
PictureBox1.Image = Image.FromFile("c:\mypic.jpg")<br />
<br />
PictureBox1.Refresh()<br />
<br />
End Sub
|
|
|
|
|
In Microsoft Project, a task's timeline can be extended by dragging the end of the bar in the Gantt chart. Is there a way to do this with the PjGrid.ocx?
|
|
|
|
|
I was trying to create my own Browser Helper Object using C#. I have made dll but I don't exactly know how to make the setup file.
I have included:
1)the dll for the BHO
2)the XML file that i am using
in the application folder in the file system editor
but i dont know what to change in the registry editor. im guessing i have to change the "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects"
but does that mean i have to create this since it isnt already in path in the registry editor? and what do i put in this place, is it my GUID?
help would be much appreciated
abhi
ps. I was using Regasm but recently is has come up with a:
"'Regasm' is not recgonized as an internal or external command, operable program or batch file"
error in the DOS prompt and the .NET 2003 prompt
any ideas what this means or why it would do this?
|
|
|
|
|
Hi,
I have a question: How can I set the datasource of a datagrid by using codes? I've been using the properties on the right side to set it.
Then I also have a problem... Why is it that whenever I use:
adodc1.recordset.addnew
ado.Recordset.Fields(0) = Trim(txtname)
ado.Recordset.Fields(1) = Trim(txtage)
ado.Recordset.Update
the data that I save in a database is automatically displayed on the datagrid. But if I use:
Set adocon = New ADODB.Connection
Set adorset = New ADODB.Recordset
adocon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "dbnames.mdb"
adorset.Open "Table2", adocon, adOpenKeyset, adLockOptimistic
adorset.AddNew
adorset.Fields(0) = Trim(txtname)
adorset.Fields(1) = Trim(txtage)
adorset.Update
the data that I save on a database don't appear automatically and it would only appear once I unload and reload my form or if I use
DTG.Columns(0) = gadors.Fields(0)
DTG.Columns(1) = gadors.Fields(1)
DTG.Columns(2) = gadors.Fields(2)
DTG.Columns(3) = gadors.Fields(3)
wherein the problem is that it overwrites the first record on a datagrid and once I unload and reload, that's the only time that the new record would be placed at the end.
I can't use the movenext and moveprevious properly as well whenever I use this type of setup.
Thanks....
|
|
|
|
|
i want to retrieve the hardware details of my system like the mouse connected to my system, the keyboard details
|
|
|
|
|
Do you mean through VB or just visualy through windows?
Second option: Click Control Panel, System, Hardware Tab, then Device Manager
Later
|
|
|
|
|
In code, you could use the System.Management namespace and WMI.
RageInTheMachine9532
|
|
|
|
|
thank you i will try it out
|
|
|
|
|
In code, you could use the System.Management namespace and WMI.
RageInTheMachine9532
|
|
|
|