|
You are right about the code. It is working for cmd.exe or notepad.exe.. I also tested the code below tried a trick to work on cmd but second writeline command executes for cmd.exe only. I also tried SendKey.SendWait(). Do you think there is something to do with security permissions? Because when I make RedirectStandardInput = True, command window is opened but not responding(blank). That's why I am saving the debug info into a txt file.
Dim objProcess As New Process
With objProcess.StartInfo
.UseShellExecute = False
.CreateNoWindow = False
.FileName = "cmd"
.RedirectStandardInput = True
.RedirectStandardOutput = True
.RedirectStandardError = False
End With
objProcess.Start()
Dim param(2) As String
param(0) = Chr(34) & CurDir() & "/mon.exe" & Chr(34) & " 10.0.0.99 4000 > C:\a.txt"
param(1) = "SET IP 10.0.0.98 > C:\b.txt"
kb.WriteLine(param)
kb.WriteLine(param(1))
B.B.
|
|
|
|
|
Sorry for the confusion. I couldn't make it run on notepad also. Could you post me a sample code to print on notepad other than the one below.
Dim objProcess As New Process
With objProcess.StartInfo
.UseShellExecute = False
.CreateNoWindow = True
.FileName = "notepad"
.RedirectStandardInput = True
.RedirectStandardOutput = False
.RedirectStandardError = False
End With
objProcess.Start()
Dim kb As StreamWriter = objProcess.StandardInput
kb.WriteLine("A1233 ")
I assume StreamWriter acts as keyboard but it is not. Maybe there is something small I am missing. I have to leave now. Appriciated for your help. Regards
B.B.
|
|
|
|
|
Actually, there's something large you're missing. You can't redirect Notepad because there are no streams in a Windows app to redirect. You can only do this with DOS applications that use the standard console and keyboard devices themselves, like the FTP app (FTP.EXE) that comes with Windows.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
By adding System.Environment.NewLine into writeline command, it is working now. Thanks for your help and support.
' The code below enables you to run a command
' window application (exe), and send special input
' commands to that exe application.
'Execute mon.exe file by creating a new process
Dim objProcess As New Process
With objProcess.StartInfo
.UseShellExecute = False
.CreateNoWindow = True
.WorkingDirectory = CurDir()
.FileName = "mon.exe"
.Arguments = " " & ipno & " 4000"
.RedirectStandardInput = True
.RedirectStandardOutput = True
.RedirectStandardError = False
End With
objProcess.Start()
Dim sIn As StreamWriter = objProcess.StandardInput
Dim sOut As StreamReader = objProcess.StandardOutput
Dim s as String
sIn.AutoFlush = True
sIn.Write("SET IP " & ipnoNEW & System.Environment.NewLine)
s = sOut.ReadToEnd()
objProcess.WaitForExit(5)
If Not objProcess.HasExited Then
objProcess.Kill()
End If
MsgBox(s)
B.B.
|
|
|
|
|
barkanb wrote: sIn.Write("SET IP " & ipnoNEW & System.Environment.NewLine)
Or, you could have just used sIn.WriteLine("SET IP" & ipnoNEW) .
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have an issue where the NumericUpDown box is diplaying too many values.
I have a simple NumericUpDownBox with the minimum set to 1 and the maximum set to 4, but can enter multiple digits on the control and I need to prevent this.
By using the KeyDown event, I am able to prevent the user from entering anything but 1, 2, 3, 4, and a few special keys like backspace, left-right arrows and delete. However, I can still press 4444444 in the display box.
I tried to coerce the code to over-write the digit with any valid key pressed. For example if "1" is pressed, then the value gets set to 1. But since it's not a .text display, the display is not getting changed.
Here is the code I am using:
Private Sub nudNUMC_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles nudNUMC.KeyDown, nudNUMD.KeyDown
Dim nud As NumericUpDown = sender
'Allowed Keycodes:
' KeyCode 49 = 1 : KeyCode 97 = NumKey 1
' KeyCode 50 = 2 : KeyCode 98 = NumKey 2
' KeyCode 51 = 3 : KeyCode 99 = NumKey 3
' KeyCode 52 = 4 : KeyCode 100 = NumKey 4
If (e.KeyCode >= 49 And e.KeyCode <= 52) Or (e.KeyCode >= 97 And e.KeyCode <= 100) Then
Select Case e.KeyCode
Case 49, 97
nud.Value = 1
Case 50, 98
nud.Value = 2
Case 51, 99
nud.Value = 3
Case 52, 100
nud.Value = 4
End Select
nud.Update()
ElseIf e.KeyCode = 8 Or e.KeyCode = 37 Or e.KeyCode = 39 Or e.KeyCode = 46 Then
'Ok
' KeyCode 8 = Backspace
' KeyCode 37 = Left Arrow
' KeyCode 39 = Right Arrow
' KeyCode 46 = Delete
Else
e.Handled = True
e.SuppressKeyPress = True
End If
End Sub
I was able to create a new project, add two NumericUpDown boxes named nudNUMC and nudNUMD with their MIN set to 1 and MAX set to 4 to isolate this scenario.
Thank you for any help and advice, Chris.
|
|
|
|
|
All you have to do is check the length of the string in the Text property of the NumericUpDown control. If it's greater than or equal to 1, don't allow the keystroke to be processed.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
This is using the VB.Net 2005 Express edition and did not see a Text property for the NumericUpDown control from the design or in the intellisense. However, when I type nud.Text, it is indeed showing this value.
I added this bit in and it is working like I want:
If (e.KeyCode >= 49 And e.KeyCode <= 52) Or (e.KeyCode >= 97 And e.KeyCode <= 100) Then
'start new code block
If nud.Value.ToString.Length >= 1 Then
e.Handled = True
e.SuppressKeyPress = True
End If
'end new code block
Thank you very much for your help.
Regards, Chris
|
|
|
|
|
I don't trust Intellisense to tell me everything about a control. I alwasy go for the documentation on it.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
hello
i have a form in vb.net and i want to change the text of the controls in other language using xml but i have a problem:after i changed the text in controls the size of the controls is not the same.
thanks
|
|
|
|
|
The controls are resizing themselves because that's their default behavior. Click on each control and, in the Properites window, look for the AutoSize property and change it to False.
The problem with this is that you run the risk of the controls new text exceeding the size of the control, cutting off portions of the text.
For more information on how it's normally done, see this[^] on MSDN.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have an app with several dialogs, that I have disabled the controlbox. Works fine on my development machine. However when I installed at a customer site, I found that the dialogs did not show properly - the lower 25% of the dialogs were 'cut off'. I checked the screen resolution, all machines have XP.
All the other windows show fine, just the ones without the controlbox are the problem.
|
|
|
|
|
Hi,
Perhaps you are facing the same problem I once encountered, when part of the controls on my form just fell outside the edge of the form on a certain PC, but not on any other.
On the problem PC, please check: Display Properties > Settings > Advanced > General > Display > DPI Setting.
In my case this was set to larger than Normal size (96 DPI) . If this is the case for you too, just set it back to normal, and try your app.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I discovered a common thread in the two windows that had probelms: I set controlbox to false.
Once I set the controlbox to true, the entire window was visible!
Thanks for the input.
|
|
|
|
|
Here is my function. It opens XML file and reads a value that associated with a key. However, it is giving me "Invalid Operation" error. I couldn't figure out where the hack error is. XML file is residing under my currentdirectory where the application is. If you tell me the solution, I would really appreciate it.
Private Function GetConfigParameter(ByVal MyKey As String) As String
Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode = Nothing
XmlDocument.Load(Environment.CurrentDirectory & "\app.con")
XmlNode = XmlDocument.DocumentElement.SelectSingleNode_("//configuration/AppDefaultValues/add[@key=""" & MyKey & """]")
GetConfigParameter = XmlNode.Attributes.GetNamedItem("value").Value
XmlDocument = Nothing
End Function
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
You can start by NOT naming your variables the same as class names, for example:
Dim XmlDocument As New XmlDocument
is a bad idea. This is because you can give yourself a headache wondering why the compiler is complaining about Static and Instance members, when your code looks correct.
Change the names to something less confusing...
Private Function GetConfigParameter(ByVal MyKey As String) As String
Dim doc As New XmlDocument
Dim node As XmlNode
' It's a bad idea to use CurrentDirectory, simply because the current directory
' can change during the execution of your app.
doc.Load( Path.Combine(Application.StartupPath, "app.con") )
node = doc.DocumentElement.SelectSingleNode("//configuration/AppDefaultValues/add[@key=""" & MyKey & """]")
Return node.Attributes.GetNamedItem("value").Value
End Function
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave I will look at it...
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Hello,
Is it possible to use the GridView Component in VB.NET?
If yes how can I add it to my project?
Thank you,
Eric H.
|
|
|
|
|
Which version of VB.NET (.NET Framework) are you using? GridView showed up in the .NET Framework 2.0, and it should be in the ToolBox. You add it to your Web Form just like any other control.
Anything further and you'll have to provide more detail as to what the exact problem is.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am using VB.NET (Framework 2.0)
The problem is this component is a web component. Therefore, I don't see it in the toolbox list. I tried to add it as a part of the toolbox but I didn't success.
Eric H.
|
|
|
|
|
If your writing a Windows Forms app, then it wont show in the ToolBox. GridView only works in an ASP.NET app. It's in the ToolBox under the Data tab ... or did I miss something in your posts??
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You understand write, I am writing a windows form application.
What can I use instead GridView?
Have you got some example to use the instead component?
Thank you much
Eric H.
|
|
|
|
|
ayeleteric wrote: You understand write, I am writing a windows form application.
This is the first time you mentioned that.
ayeleteric wrote: What can I use instead GridView?
Windows Forms uses the DataGridView. Again, under the Data tab in the ToolBox.
ayeleteric wrote: Have you got some example to use the instead component?
The Web has thousands of them. All you have to do is Google for "VB.NET DataGridView tutorial".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
My problem is to open design view of report so that end user can design report acording to his choice...
is it possible to open design view of rdlc or crystal report at runtime to give control to end user.
sweety
|
|
|
|