|
You lose. Simon didn't say.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
hi...
need help on urgent basis.
i wanna make a graph for my few excel files containing different datas . unable to get the code how to call those excel files for making graphs..
thanks for your help in advance..
|
|
|
|
|
|
I'm programming for my G15 LCD Keyboard.
When i press a button on the LCD it triggers the "ButtonPressed" event. When i press button 2 i want it to Add Handlers for my KeyboardHook for my Calculator.
The idea is that when i press button 2, my screen changes and my KeyboordHook starts listening, then i can enter calculations on my keyboard that are displayed on my LCD and processed when i hit enter.. Simple enough..
The problem is that i can't seem to find a way to add the Handlers for it while i'm already in an event..
The ButtonPress Event that starts the Calculator:
Dim Calculator As New Tools.LCDCalculator
Public Function ButtonPress(ByVal device As Integer, ByVal dwButtons As Integer, ByVal pContext As System.IntPtr) As Integer
Calculator.StartCalculator()
End Function
And here's the Calculator Class:
Public Class LCDCalculator
Public Active As Boolean
Public Sub StartCalculator()
Debug.WriteLine("Active")
AddHandler HookManager.KeyPress, AddressOf HookManager_KeyPress
End Sub
Public Sub StopCalculator()
Debug.WriteLine("Inactive")
RemoveHandler HookManager.KeyPress, AddressOf HookManager_KeyPress
End Sub
Public Sub HookManager_KeyPress(sender As Object, e As KeyPressEventArgs)
Debug.WriteLine(String.Format("KeyPress - {0}", e.KeyChar))
e.Handled = True
End Sub
End Class
I thought it might be threading or something so i tried doing this:
Task.Run(Sub() Calculator.StopCalculator())
But no such luck ...
I can start the Calculator from anywhere else and it works flawlessly, but when i try adding that handler from in the ButtonPress event it doesn't seem to work..
Please advise
|
|
|
|
|
Being inside and event handler has no bearing at all on the ability to add or remove event handlers.
The problem lies elsewhere, though I can't say where because there is insufficient code and description of how you have things setup. For example, does the KeyboardHook work in a test application?
|
|
|
|
|
I am building a windows form, using VB in VS2015.
I have a number of objects on the form. I added MSFlexGrid. Clicked F4 to edit properties, changing name, number of rows and columns.
The MsFlexgrid object then displays as a dotted box. If I try clicking on it it disappears.
I thought it might have been because I picked one column and two rows, so I have tried different number of rows and columns, no difference.
Anyone else had this problem and know the fix please ?
Thanks for reading
|
|
|
|
|
Why are you even using the FlexGrid? It's older than dirt itself. The modern replacement is the DataGridView.
|
|
|
|
|
Because I'm converting a VB5 project.
|
|
|
|
|
That is not any reason to use a COM object that is truly ancient. Replace it with a datagridview and be done with it.
The up side is there are plenty of examples on how to use a DGV.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you - what you say makes sense. Are there any tips you can allude to on converting to the new version please ?
|
|
|
|
|
Not really, I would probably search here for some DGV examples and download the article code and work through binding the data to the DGV.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'll give that a go, in a test project I am running, before using on live one. Do you know of any things the new one won't do that the old version would do ? I can't imagine a problem because the use was quite simple, but .....
|
|
|
|
|
No.
Honestly, I haven't used the old one in so long I can't even remember what it looks like.
The differences between the old VB5 and VB.NET are so huge they really are different languages. I would not be doing a line-by-line conversion of the app. I'd be scrapping the old code and completely rewriting from the ground up. You'll probably find that you'll be using less code too.
|
|
|
|
|
I am running into the issue:Access Denied when calling bcp from Windows 2012 server.
Any idea what it could be? Running in elevated mode.
Dim ps As New System.Diagnostics.Process
ps.StartInfo.UseShellExecute = False
ps.StartInfo.Domain = Domain
ps.StartInfo.UserName = UserName
Dim pword As New System.Security.SecureString()
For Each c As Char In Password
pword.AppendChar(c)
Next
ps.StartInfo.Password = pword
ps.StartInfo.LoadUserProfile = False
ps.StartInfo.WorkingDirectory = "E:\"
ps.StartInfo.FileName = "cmd.exe"
ps.StartInfo.Verb = "runas"
ps.StartInfo.Arguments = " bcp " + DbTable + " in " + SourceFile + " -m " + MaxErrors + " -f " & FMTFile & " -e " & ErrorFile & " -o " & LogFile & " -S " & ServerName & " -T"
ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
ps.Start()
ps.WaitForExit()
|
|
|
|
|
First, you don't need the RunAs verb line at all.
Next, the command line you build is this:
cmd bcp something in something -m ...
That command line is wrong for CMD.
Next, you don't even run CMD. Your Filename line should be "bcp". The Arguments should be almost everything you already have in existing statement.
ps.StartInfo.FileName = "bcp"
ps.StartInfo.Arguments = String.Format("{0} in {1} -m {2} -f {3}...", DbTable, SourceFile, MaxErrors, FMTFile, ...
ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
ps.Start()
ps.WiatForExit()
On top of everything else, in order for the Hidden window option to work you have to change the UseShellExecute property to True.
|
|
|
|
|
Hello everyone,
I've been looking for the code to print my full DataGridView with Visual Basic 2010 Express for a long period and I tested all codes that are displayed with searches on google but in vain.
But finally I find a C # code that I converted to VB which suits me perfectly but the only problem is that it runs infinitely (infinite loop at the number of pages)
NOTE: The code doesn't generate an error and it's an urgent case because I need it for my job.
Thanks,
Here is my code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
Dim iHeaderHeight As Double
Dim iLeftMargin As Integer = e.MarginBounds.Left
Dim iTopMargin As Integer = e.MarginBounds.Top
Dim bMorePagesToPrint As Boolean = False
Dim iTmpWidth As Integer = 0
If bFirstPage Then
For Each GridCol As DataGridViewColumn In DataGridView_impot.Columns
iTmpWidth = CType(Math.Floor(CType((CType(GridCol.Width, Double) / (CType(iTotalWidth, Double) * (CType(iTotalWidth, Double) * (CType(e.MarginBounds.Width, Double) / CType(iTotalWidth, Double))))), Double)), Integer)
iHeaderHeight = (CType(e.Graphics.MeasureString(GridCol.HeaderText, GridCol.InheritedStyle.Font, iTmpWidth).Height, Integer) + 11)
arrColumnLefts.Add(iLeftMargin)
arrColumnWidths.Add(iTmpWidth)
iLeftMargin = (iLeftMargin + iTmpWidth)
Next
End If
Dim iRow As Double
While (iRow <= (DataGridView_impot.Rows.Count - 1))
Dim GridRow As DataGridViewRow = DataGridView_impot.Rows(iRow)
iCellHeight = (GridRow.Height + 5)
Dim iCount As Integer = 0
If (iTopMargin + (iCellHeight >= (e.MarginBounds.Height + e.MarginBounds.Top))) Then
bNewPage = True
bFirstPage = False
bMorePagesToPrint = True
Exit While
Else
If bNewPage Then
e.Graphics.DrawString(Me.lbl_rs.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), Brushes.Black, e.MarginBounds.Left, (e.MarginBounds.Top - (e.Graphics.MeasureString(Me.lbl_rs.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), e.MarginBounds.Width).Height - 13)))
e.Graphics.DrawString(Me.lbl_date_now.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), Brushes.Black, (e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(Me.lbl_date_now.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), e.MarginBounds.Width).Width)), (e.MarginBounds.Top - (e.Graphics.MeasureString(Me.lbl_rs.Text, New Font(New Font(DataGridView_impot.Font, FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13)))
iTopMargin = e.MarginBounds.Top
For Each GridCol As DataGridViewColumn In DataGridView_impot.Columns
e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight))
e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font, New SolidBrush(GridCol.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight), strFormat)
iCount = (iCount + 1)
Next
bNewPage = False
iTopMargin = (iTopMargin + iHeaderHeight)
End If
iCount = 0
For Each Cel As DataGridViewCell In GridRow.Cells
If (Not (Cel.Value) Is Nothing) Then
e.Graphics.DrawString(Cel.Value.ToString, Cel.InheritedStyle.Font, New SolidBrush(Cel.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), CType(iTopMargin, Single), CType(arrColumnWidths(iCount), Integer), CType(iCellHeight, Single)), strFormat)
End If
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iCellHeight))
iCount = (iCount + 1)
Next
End If
iRow = (iRow + 1)
iTopMargin = (iTopMargin + iCellHeight)
End While
If bMorePagesToPrint Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
Catch exc As Exception
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
|
|
|
|
|
"Urgent" doesn't work too well here - it tends to annoy people who are spending their time answering questions on a voluntary basis.
And why do you repost your exact same question?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
actually, I need some help and there is no one answering
|
|
|
|
|
Well, as I said, we're volunteers here. So you have to accept that it may take a while to get an answer. Marking it as "urgent" can very well lead to the opposite of the intended effect.
And your problem sounds like it can easily be identified by running your code step by step in the debugger. Did you do that?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thank you Sascha for you're answer
Yes I know that you are volunteers but i said it's "urgent" because it been so long that i'm looking for a solution.
I've run it step by step and it dosen't make changes and for that reason i didn't know what to do :/
and i'm sure that the problem is in that part.
Thanks again
|
|
|
|
|
iRow is a Double which makes little sense for a row counter. I don't think it's the cause of the problem but I'd change it to Integer .
As iRow is incremented unconditionally and all other loops are For-Each-loops it's not obvious to me where and why this code would loop indefinitely.
Dorsaf Ouersighni wrote: I've run it step by step and it dosen't make changes So your next task for debugging is to determine why it doesn't make changes (which would lead to a loop termination).
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I really don't know why The WHY is what i'm looking for.
and As you said " all other loops are For-Each-loops it's not obvious to me where and why this code would loop indefinitely. "
Even when i changed iRow to Integer, nothing changes and there is nothing warning in the project; no erreurs and no warning
That's disturbing
|
|
|
|
|
Dorsaf Ouersighni wrote: I really don't know why The WHY is what i'm looking for. If a loop gets executed indefinitely it's because its condition to keep running keeps evaluating to true. So, if it's the while-loop that executes indefinitely
While (iRow <= (DataGridView_impot.Rows.Count - 1))
then it has to be because iRow always has a value lower than the amount of rows. That's not intended of course - so you would have to find out (using the debugger) why this is so in order to fix it.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks a lot Sascha
I think that's TRUE. When i changed iRow bigger than the condition, it stop executing indefinitely.
I will try to fix it immediatly.
I really appreciate you're effort and thank you very much
I will send you back the result
Have a nice day
By the way you have a beautiful name
|
|
|
|
|
I'm guessing that the infinite looping doesn't occur within the posted Sub. Instead, I assume, e.HasMorePages always gets set to true so that the PrintPage-event automatically gets fired again so the Sub gets called again. You can verify this by placing a debug-breakpoint on this line:
If bMorePagesToPrint Then
When you get there, inspect the value of bMorePagesToPrint (I suspect it will always be true ) and then press F5 (continue execution until next breakpoint) which will probably get you to that same line again and again.
If this is the case, then the condition on this line
If (iTopMargin + (iCellHeight >= (e.MarginBounds.Height + e.MarginBounds.Top))) Then never evaluates to false so that bMorePagesToPrint always gets set to true . Then you would have to figure out why this condition never evaluates to false - this is hard to guess for me by looking at the code only.
Dorsaf Ouersighni wrote: By the way you have a beautiful name Thank you
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|