|
Yone,
Wouldn't that look for an exact match instead of searching the string for those characters?
Nathan
|
|
|
|
|
Wow, how dumb of me. (i guess i should stop surfing the web in bed)
Thanks a million for correcting me.
|
|
|
|
|
i have to check for a particular condition, and if the user doesnt satisfy that condition, i need to logoff him forcibly. (OS: WindowsXP and Win2K)
obviously i have to use a windows service, but i couldnt figure out the code to loghim off.
can anyone please help
|
|
|
|
|
Though it doesn't force a logoff the code below will programatically lock the workstation using an API call
Declare Function LockWorkStation Lib "user32.dll" () As Long
Call LockWorkStation() after condition evaluation.
I'll look around for a better example.
|
|
|
|
|
Here is an API call that forces a logoff BUT I'm still trying to work out a bug - it throws an exception during debug saying that I've unbalanced the stack, though this exception isn't thrown when I run the code from outside the IDE.
So basically what I'm saying is that the code below ain't perfect but it's closer to what you asked for than the previous example.
This function takes two arguments. First argument is one or more flags (the declared constants) instructing windows how to shutdown. Second argument is reserved (I don't know why yet), and is set to zero.
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Declare Function ExitWindowsEx Lib "user32" Alias _
"ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved _
As Long) As Long
then when needed call
ExitWindowsEx(EWX_FORCE Or EWX_LOGOFF, 0)
I'm still trying to figure it out better. Sorry that the help I've provided isn't very informative or perfect.
|
|
|
|
|
You've unbalanced the stack because your using the wrong data types for the parameters and return values. I'll make an educated guess and say that you lifted some VB6 code and tried to use it under VB.NET without any modification.
Under VB6, the Long type is a 32-bit signed integer, while under VB.NET, the Long type is a 64-bit signed integer. This is why the stack is unbalanced. If you're going to use VB6 code, you have to change all the Long's to Integers under VB.NET:
Public Const EWX_LOGOFF As Integer = &H0
Public Const EWX_POWEROFF As Integer = &H8
Public Const EWX_REBOOT As Integer = &H2
Public Const EWX_RESTARTAPPS As Integer = &H40
Public Const EWX_SHUTDOWN As Integer = &H1
Public Const EWX_FORCE As Integer = &H4
Public Const EWX_FORCEIFHUNG As Integer = &H10
Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer
Oh! You also don't need the 'Alias' clause if the name you gave the function matches the name in the library.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
"Wow" looks neat, you got my 5
|
|
|
|
|
Thanks for corrections, I seldom have need to use API calls.
Dave Kreskowiak wrote: I'll make an educated guess and say that you lifted some VB6 code
Close - API Viewer 2004
Dave Kreskowiak wrote: Under VB6, the Long type is a 32-bit signed integer, while under VB.NET, the Long type is a 64-bit signed integer.
I thought Long was Long regardless, my mistake
Great advice, thanks!
|
|
|
|
|
Dear friends,
thanks for the timely help.
|
|
|
|
|
How can I create a shared memory zone? I'm using this zone to create a bridge between two aplications. The code is written in vb.net.
A perfect exemple for this is having a printer listener and a program that needs to print throught the printer listiner. I found another way to do that fast but accesing a shared memory zone is still a problem form me.
How can i use the api's for creating and comunicating threads from vb.net. i don't have the strucures needed?
P. Sorin
|
|
|
|
|
i have no idea about this but look into appdomain. this may allow you to access what you need.
else
put a listener on your printer program and have you app call it using TCP/UDP to give it instructions.
|
|
|
|
|
You might want to look at the source in this[^] article for an example of implementing shared memory.
There's also this[^] article and this[^] one that get into a bit.
But, in all cases, you'll have to manage this shared area yourself. There is no support in the .NET BCL for shared memory or memory mapped files.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all,
A simple question.Please help me in this.
Const ma111VID As Short = &H846S
What does the "S" stand for in &H846S?
Const RFCMD_REPRGM_CONFIRM As Int16 = &H691A
What does the "A" stand for in &H691A?
|
|
|
|
|
Dont double post!
Posted by The ANZAC
|
|
|
|
|
ashwath1979 wrote: Const ma111VID As Short = &H846S
The literal type character 'S' just means that the number, hexadecimal 846, should be forced to a Short datatype. In this case, it's meaningless because the type that the literal is being assigned to is already a Short. In other words, the 'S' is redundant.
ashwath1979 wrote: Const RFCMD_REPRGM_CONFIRM As Int16 = &H691A
The 'A' is part of the number, not like the 'S' in your previous example. The '&H' part specifies that the number is in hexadecimal format. Hexadecimal is Base16, which has values that go from 0 to F (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). In your example, the number in hex is 691A, or decimal 26906.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Hi there,
I Have a Dataset(vb.net) and that can be contain apostrophes(') in fields. I need to replace all apostrophe with the space character. Is there any way to solve the simple update (without loop) ?
thanks
Murat TURHAN
|
|
|
|
|
From where r u filling the Dataset?
If you are filling it from the DB then the best solution is to replace it in the query.
Mubashir
Every job is a self portrait of the person who did it.
|
|
|
|
|
Yes i m filling from DB but source is constant changing.
therefore tables and fields are uncertain. Dataset is creating dinamically.
Murat TURHAN
|
|
|
|
|
Const ma111VID As Short = &H846S
What does the "S" stand for in &H846S.
Const RFCMD_REPRGM_CONFIRM As Int16 = &H691A
What does the "A" stand for in &H691A.
|
|
|
|
|
Is there something wrong with this line ...
Dim totValue As Integer = CInt(tblDataTable.Compute("SUM(Value)", "Product = 'P199'"))
It doesn't seem to do anything. I put totValue into a messagebox immediately after it, but it simply ignores it and carries on - infact a Try ... Catch in the same area is invoked unnecessarily.
So, I tried removing the 'filter' part of compute (I'm still new to this, and I believe that its optional), so that I had:
Dim totValue As Integer = CInt(tblDataTable.Compute("SUM(Value)"))
But this just underlines the tblDataTable.Compute("SUM(Value)") part in my code, with the 'tooltip', "Argument not specified for parameter 'filter' of 'Public function compute'.
What am I doing wrong?
|
|
|
|
|
penguin5000 wrote: CInt
You should not use this, it's VB6 nastiness. Use Convert.ToInt32 instead, or int.Parse.
The MSDN samples put Sum, not SUM. I wonder if it's case sensitive ?
I'd break it into steps, so you can see which one fails.
Christian Graus - C++ MVP
|
|
|
|
|
Unfortunately, it still isn't working. Is it the way I'm constructing my DataTable? The relevant section is as follows. I'd really appreciate some pointers:
Dim myStreamReader As StreamReader = New StreamReader(txtFilePath.Text)<br />
Dim strLine As String<br />
Dim strProdCode As String<br />
Dim strTransCode As String<br />
Dim intQuantity As Integer<br />
Dim intValue As Integer<br />
Dim intRunningQuantityTotal, intRunningValueTotal As Integer<br />
Dim intNumberOfRows As Integer<br />
Dim tblDataTable As New DataTable<br />
<br />
tblDataTable = New DataTable("TrxContents")<br />
<br />
Dim colProds As DataColumn = New DataColumn("Product")<br />
Dim colTrans As DataColumn = New DataColumn("Trans Code")<br />
Dim colQty As DataColumn = New DataColumn("Quantity")<br />
Dim colValue As DataColumn = New DataColumn("Value")<br />
Dim row As DataRow<br />
<br />
tblDataTable.Columns.Add(colProds)<br />
tblDataTable.Columns.Add(colTrans)<br />
tblDataTable.Columns.Add(colQty)<br />
tblDataTable.Columns.Add(colValue)<br />
<br />
intRunningQuantityTotal = 0<br />
intRunningValueTotal = 0<br />
intNumberOfRows = 0<br />
intOriginalLines = 0<br />
<br />
Try<br />
<br />
Do While myStreamReader.Peek <> -1<br />
strLine = myStreamReader.ReadLine()<br />
intOriginalLines = intOriginalLines + 1<br />
<br />
If strLine.Substring(0, 1) = "K" Then<br />
row = tblDataTable.NewRow()<br />
intNumberOfRows = intNumberOfRows + 1<br />
<br />
'Read the Product Code (start at pos 6. 26 chars long)<br />
strProdCode = strLine.Substring(5, 26)<br />
row.Item("Product") = strProdCode<br />
<br />
'Read the transaction code (start at pos 63. 2 chars long)<br />
strTransCode = strLine.Substring(62, 2)<br />
row.Item("Trans Code") = strTransCode<br />
<br />
'Read the Quantity (start at pos 74. 12 chars long)<br />
intQuantity = strLine.Substring(73, 12)<br />
row.Item("Quantity") = intQuantity<br />
intRunningQuantityTotal = intRunningQuantityTotal + intQuantity<br />
<br />
'Read the Value (start at pos 86. 14 chars long)<br />
intValue = strLine.Substring(85, 14)<br />
row.Item("Value") = intValue<br />
intRunningValueTotal = intRunningValueTotal + intValue<br />
<br />
tblDataTable.Rows.Add(row)<br />
<br />
End If<br />
<br />
Loop<br />
myStreamReader.Close()<br />
<br />
Dim ds As New DataSet<br />
ds = New DataSet<br />
<br />
Dim totValue As Integer = Convert.ToInt32(tblDataTable.Compute("Sum(Value)", "Product = 'P199'"))<br />
MessageBox.Show(totValue)<br />
<br />
ds.Tables.Add(tblDataTable)<br />
Me.grdDataGrid.SetDataBinding(ds, "TrxContents")<br />
<br />
Catch<br />
<br />
... some stuff<br />
<br />
End Try
Thanks in advance.
|
|
|
|
|
Best guess, looking at this code, Value is not a numeric type, which means that Sum won't work on it.
Christian Graus - C++ MVP
|
|
|
|
|
Thanks.
A couple of minor changes:
Dim colValue As DataColumn = New DataColumn("Value", GetType(Integer))<br />
<br />
intValue = Integer.Parse(strLine.Substring(85, 14))
|
|
|
|