|
Your best source of information on this is going to be whoever wrote that library. With the information you've given, there's really nothing telling us what could be wrong.
|
|
|
|
|
I am basically an electronics student. I am currently developing a vb code to control multiple devices using bluetooth. I am making use of vb here. I am a very beginner in vb and dont have much knowledge. Please help me with examples.
Problem:
Below, I have provided the code which I developed for my project. It monitors few text files located in C:\ directory and based on that, the relevant code is sent through parallel port which I use to further purposes.
The problem occurred that I need to monitor those files. I used loop, do, if, goto, while statements. Till the end button is pressed, it needs to monitor the existence of files.
All the statements resulted in "NOT RESPONDING" state. Can anyone please help me for that. I just want my program to loop continuously from end to beginning till the end button(command2) is pressed. Then I used a check button and used if command, it also did not work.
Here is the code I wrote till now
-----------------------------------
Private Sub Command1_Click()<br />
' following sections to read file line obtained from http://www.codeguru.com/forum/archive/index.php/t-315872.html<br />
Dim strFile As String<br />
Dim PortAddress As Integer<br />
'Dim iFile As Integer<br />
Dim strContent As String<br />
Dim strContent2 As String<br />
Dim strContent3 As String<br />
Dim strContent4 As String<br />
PortAddress = &H378<br />
'TO Do Add code here to put a filename with path in strFile<br />
Label1.Caption = "light is off" 'display status<br />
Label3.Caption = "fan is off" 'display status<br />
<br />
file1 = "c:\lighton.txt"<br />
file2 = "c:\lightoff.txt"<br />
file3 = "c:\fanon.txt"<br />
file4 = "c:\fanoff.txt"<br />
'iFile = FreeFile '1=lighton.txt 2=lightoff.txt 3=fanon.txt 4=fanoff.txt<br />
'restart:<br />
Do<br />
<br />
If (Len(Dir$(file1)) <> 0) Then 'lighton.txt file existance check<br />
For j = 1 To 255<br />
Close #j<br />
Next j<br />
Open "c:\lighton.txt" For Input As #1<br />
'The following will read the first line from the file<br />
Line Input #1, strContent ' read 1st line in the file<br />
Close #1 ' close file<br />
If (strContent = "light on") Then 'check validity of file<br />
Label1.Caption = "light is on" 'display status<br />
Value = Inp(PortAddress)<br />
Value = Value Or &HF 'make lsbs high<br />
Out PortAddress, Value 'output the value<br />
End If<br />
For i = 1 To 5<br />
If (Len(Dir$(file2)) <> 0) Then 'lighton.txt file existance check<br />
For j = 1 To 255<br />
Close #j<br />
Next j<br />
Open "c:\lightoff.txt" For Input As #2<br />
'The following will read the first line from the file<br />
Line Input #2, strContent2 ' read 1st line in the file<br />
Close #2 ' close file<br />
If (strContent2 = "light off") Then 'check validity of file<br />
Label1.Caption = "light is off" 'display status<br />
Value = Inp(PortAddress)<br />
Value = Value And &HF0 'make lsbs high<br />
Out PortAddress, Value 'output the value<br />
Kill "c:\lighton.txt"<br />
Kill "c:\lightoff.txt"<br />
End If<br />
End If<br />
Next i<br />
<br />
End If<br />
<br />
<br />
<br />
' monitor for fan files<br />
<br />
If (Len(Dir$(file3)) <> 0) Then 'lighton.txt file existance check<br />
For j = 1 To 255<br />
Close #j<br />
Next j<br />
Open "c:\fanon.txt" For Input As #3<br />
'The following will read the first line from the file<br />
Line Input #3, strContent3 ' read 1st line in the file<br />
Close #3 ' close file<br />
If (strContent3 = "fan on") Then 'check validity of file<br />
Label3.Caption = "fan is on" 'display status<br />
Value = Inp(PortAddress)<br />
Value = Value Or &HF0 'make lsbs high<br />
Out PortAddress, Value 'output the value<br />
End If<br />
For i = 1 To 5<br />
If (Len(Dir$(file4)) <> 0) Then 'lighton.txt file existance check<br />
For j = 1 To 255<br />
Close #j<br />
Next j<br />
Open "c:\fanoff.txt" For Input As #4<br />
'The following will read the first line from the file<br />
Line Input #4, strContent4 ' read 1st line in the file<br />
Close #4 ' close file<br />
If (strContent4 = "fan off") Then 'check validity of file<br />
Label3.Caption = "fan is off" 'display status<br />
Value = Inp(PortAddress)<br />
Value = Value And &HF 'make lsbs high<br />
Out PortAddress, Value 'output the value<br />
Kill "c:\fanon.txt"<br />
Kill "c:\fanoff.txt"<br />
End If<br />
End If<br />
Next i<br />
<br />
End If<br />
<br />
<br />
<br />
'Sleep 1000 'Implements a 1 second delay<br />
<br />
<br />
<br />
Loop Until ((Check1.Value = 0))<br />
<br />
'GoTo restart<br />
<br />
End Sub<br />
<br />
Private Sub Command2_Click()<br />
End<br />
End Sub<br />
<br />
<br />
|
|
|
|
|
Take a look at the FileWatcher class (I think) this works for small file numbers (chokes when there are too many events.
Also you should change your loop to a timer based application, something like
Start time
Timer tick event
Turn timer off
Process directory
turn timer on
Set the tick for 1 second
|
|
|
|
|
Wow, this is some old code. Warning - This code will NOT work with VB.NET and won't work at all under a Windows NT Kernel O/S, such as WIndows 2000, XP, 2003, Vista, ...
What version of Basic is this and what O/S are you planning on running it under?
|
|
|
|
|
Hi Guys,
Im trying to build a stock system for a small cd store, iv got the basics out the way, but i need help with something a bit more complex.
The form i need to build will need to show the weekly sales for each product. The way id imagine i would build was to have a data table with the products down the side of the table and the dates ( 11/03/08 - 12/03/08 - 13/03/08 etc.) at the top. The information in the table will hold the quantity sold for that day. Everytime a sale is processed the qty will be updated on this table.
Does anybody have any idea how i could go about bulding this?
I appreciate any help i get.
Thanks
|
|
|
|
|
The logical way to do this is to have a table that logs each sale, with it's date, and you write SQL queries that build reports from that data. If the table knows when each CD was sold, then you can report on that any way you like.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I found nice example how to draw lines by mouse on form. I want to have picture as background and write lines on this picture. Is there anyone who can show me how can I put picture as background?
Imports System.Windows.Forms
Public Class frmIceTimeShots
' True while we are drawing the new line.
Private m_Drawing As Boolean
' Buffer for erasing rubberband lines.
Private m_BufferBitmap As Bitmap
Private m_BufferGraphics As Graphics
' The mouse position.
Private m_X1 As Integer
Private m_Y1 As Integer
Private m_X2 As Integer
Private m_Y2 As Integer
Private Sub SaveSnapshot()
Dim new_bitmap As Bitmap
' Make a new bitmap that fits the form.
new_bitmap = New Bitmap(Me.Width, Me.Height)
m_BufferGraphics = Graphics.FromImage(new_bitmap)
' Clear the new bitmap.
m_BufferGraphics.Clear(Me.BackColor)
m_BufferGraphics.DrawImage(new_bitmap, 0, 0)
' Copy the existing bitmap's contents into
' the new bitmap.
If Not (m_BufferBitmap Is Nothing) Then
m_BufferGraphics.DrawImage(m_BufferBitmap, 0, 0)
End If
' Save the new bitmap and graphics objects.
m_BufferBitmap = new_bitmap
End Sub
' Continue drawing the rubberband line.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseMove
' Do nothing if we're not drawing.
If Not m_Drawing Then Exit Sub
' Save the new point.
m_X2 = e.X
m_Y2 = e.Y
' Erase the previous line.
DrawForm(Me.CreateGraphics())
' Draw the new line directly on the form.
Me.CreateGraphics().DrawLine( _
Pens.Gray, m_X1, m_Y1, m_X2, m_Y2)
End Sub
' Redraw the saved buffer.
Private Sub DrawForm(ByVal gr As Graphics)
If Not (m_BufferBitmap Is Nothing) Then _
gr.DrawImage(m_BufferBitmap, 0, 0)
End Sub
Private Sub frmIceTimeShots_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
' Do nothing if this isn't the left mouse button.
If e.Button <> MouseButtons.Left Then Exit Sub
m_Drawing = True
' Save a snapshot of the form.
SaveSnapshot()
' Save the current mouse position.
m_X1 = e.X
m_X2 = e.X
m_Y1 = e.Y
m_Y2 = e.Y
End Sub
' Finish drawing the new line.
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseUp
' Do nothing if we're not drawing.
If Not m_Drawing Then Exit Sub
m_Drawing = False
' Save the new point.
m_X2 = e.X
m_Y2 = e.Y
' Draw the new line permanently on the buffer.
m_BufferGraphics.DrawLine( _
Pens.Blue, m_X1, m_Y1, m_X2, m_Y2)
' Redraw to show the new line.
DrawForm(Me.CreateGraphics())
End Sub
' Redraw the form.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles _
MyBase.Paint
DrawForm(e.Graphics)
End Sub
End Class
|
|
|
|
|
Very quickly, I can see at least one major flaw in your code, where you've got a resource leak. You're not disposing of your graphics object when you're done with it. When you create a Graphics object, you Dispose it. The result we be the eventual exhaustion of the Windows handle pool. You'll start to get some very strange behavior and error messages, system-wide, when this happens.
When you get the final coordinates of the line being drawn, create a graphics object on the bitmap image you're using as a background, draw the line, dispose of the graphics object, then just set the controls background to the new background image.
|
|
|
|
|
Hello,
I have the following:
A double varialble for ex. 12.5
When i want to make a string of the variable id do the following system.convert.tostring (variable)
The result is indead a string but in the following format 12,5 when i insert that to my SQL 2005 server the SQL makes 125 into the database isntead of 12.5.
When i manualy insert a 12.5 into the SQL there is no problem so 12.5 is in the database.
So i think i have a converison problem .
I dont want to change the regional setting of the pc because when changing those other programs will not work like they should.
So i look for a solution to change the convert method so i can convert to tring but with a . instead of a , or tell to SQL server 2005 that it has to accept , ans use it as a comma.
Any suggestions are very welcome
Thanks
DCAUB
|
|
|
|
|
DCAUB wrote: When i want to make a string of the variable id do the following system.convert.tostring (variable)
The result is indead a string but in the following format 12,5
The ToString is taking into account your locale. Send the ToString method a CultureInfo object of the locale you want to use in the conversion.
DCAUB wrote: when i insert that to my SQL 2005 server
Then you are attempting it INJECT the value into a SQL string. Don't do that. It will cause you problems as it leaves your application open to SQL Injection Attacks.
DCAUB wrote: So i think i have a converison problem .
No. You have a security problem.
DCAUB wrote: I dont want to change the regional setting of the pc because when changing those other programs will not work like they should.
No need. (1) You can set a locale briefly on methods that accept it. (2) Fiddling about with string conversion won't solve the underlying gaping security hole you have.
DCAUB wrote: So i look for a solution to change the convert method so i can convert to tring but with a . instead of a , or tell to SQL server 2005 that it has to accept , ans use it as a comma.
Pass the value as a double directly to SQL Server. Don't inject it into SQL strings.
For more information on securing youself against SQL Injection Attacks please read SQL Injection Attacks and some tips on how to prevent them[^]
|
|
|
|
|
Hello,
Can you give me a small example please.
I have the following
Total as double = 12.5
What i do is :
Sqlstring = "Insert Into test (total) Values ('" + system.convert.tostring (total) + "')"
When checking the sql string there is Insert Into test (total) Values ('12,5') there it is wrong.
After that i execute the above SQL statement
Thanks for helping me out.
Dcaub
|
|
|
|
|
DCAUB wrote: Can you give me a small example please.
I refuse to knowing give examples that will blow security holes in your application.
Read the article I linked to. That will show you how to do it properly that does not require you to convert anything, and is secure.
|
|
|
|
|
Hello,
how can i easily send a string over the internet to another pc, only to know that IP Adress?
I know it's possible with Winsock or Net.Sockets ...
but i am really really new in this area and i don't know how to do that... so it would be great if somebody has a really easy example for me....
I want to do it if possible with a timer, so i have a server application and a client application, the server app sends the string and the client application gets the string, is it possible then to let the client send informations to the server too?
Thank you
|
|
|
|
|
This is done using Winsock (sockets). There are examples all over the 'Net. "Simple" is a matter of understanding. What I would call "simple" is probably not what you would call it.
softwarejaeger wrote: I want to do it if possible with a timer,
Is there something you don't understand about a timer??
<blockquote class="FQ"><div class="FQA">softwarejaeger wrote:</div>the server app sends the string and the client application gets the string, is it possible then to let the client send informations to the server too?</blockquote>
Of course it is.
"vb.net simple sockets"[^]
|
|
|
|
|
Hi
Can Anybody tell me how can i update my database by editing data visible from database in DataGrid
shaeron
|
|
|
|
|
|
Hi All,
This is my first question.
I have been in a couple of months developing application using VB.NET Compact Edition. I have a problem.
My form have listbox, textbox and other data bound controls. If I update the data using ExecuteNonQuery(), how do I reflect the change in those data bound controls?
Any help would be appreciated.
Thanks you,
Eko SW
|
|
|
|
|
Hello everybody,
The code below is a VBA code I originally created for a MACRO in excel 2003. My goal is to be able to execute the code below from a VB 2005/VB.NET module/application. In other words, could someone help me out with correcting the syntax errors? I'm quite confident about my excel VBA skills, but I am so stuck on converting this to VB 2005/VB.NETAny help would be so tremendously appreciated. I've tried reseraching what I can do, but unfortunately, I'm completely stuck.
Module ShelfList
Sub calculateAmount()
Dim boAmount As Decimal
Dim boUnit As Integer
Dim shippedAmount As Decimal
Dim shippedUnit As Integer
boAmount = "0.00"
boUnit = 0
shippedAmount = "0.00"
shippedUnit = 0
Dim range1 As Range
range1 = ActiveSheet.Range("A1")
Do While range1.Value <> "Not Filled / On Order"
range1 = range1.Offset(1, 0)
Loop
range1 = range1.Offset(1, 0)
Do While range1.Value <> "Other"
range1 = range1.Offset(0, 17)
boAmount = boAmount + range1.Value
If range1.Value <> "" Then boUnit = boUnit + 1
range1 = range1.Offset(1, -17)
Loop
range1 = range1.Offset(0, 17)
'range1.Value = boAmount
range1 = range1.Offset(1, 0)
Do While range1.Value <> ""
shippedAmount = shippedAmount + range1.Value
If range1.Value <> "" Then shippedUnit = shippedUnit + 1
range1 = range1.Offset(1, 0)
Loop
'range1.Value = shippedAmount
'range1.Select
Sheets.Add()
Dim range2 As Range
range2 = ActiveSheet.Range("A1")
range2.Value = "Back Order Amount"
range2 = range2.Offset(0, 1)
range2.Value = boAmount
range2 = range2.Offset(1, -1)
range2.Value = "Back Order Units"
range2 = range2.Offset(0, 1)
range2.Value = boUnit
range2 = range2.Offset(1, -1)
range2.Value = "Shipped Amount"
range2 = range2.Offset(0, 1)
range2.Value = shippedAmount
range2 = range2.Offset(1, -1)
range2.Value = "Shipped Units"
range2 = range2.Offset(0, 1)
range2.Value = shippedUnit
Columns("A:A").EntireColumn.AutoFit()
Columns("B:B").EntireColumn.AutoFit()
Columns("A:A").Select()
Selection.Font.Bold = True
ActiveSheet.Name = "Totals"
ActiveWorkbook.Save()
End Sub
End Module
|
|
|
|
|
Where are you stuck?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
When I first tried to use the Excel macro code in VB 2005, it was clear that "Range" was not a valid data type therefore the code falls apart after "Dim range1 As Range." I'm just not sure how Excel data is read by VB and I'm not sure how to address the incoming data. In Excel, I use "ActiveSheet" and "Columns" to comb through the data but I am unable to find any information on how to do create an application in VB 2005 that will do something similar.
See underlined sections below as an example.
<br />
Module ShelfList<br />
<br />
Sub calculateAmount()<br />
<br />
Dim boAmount As Decimal<br />
Dim boUnit As Integer<br />
Dim shippedAmount As Decimal<br />
Dim shippedUnit As Integer<br />
<br />
boAmount = "0.00"<br />
boUnit = 0<br />
shippedAmount = "0.00"<br />
shippedUnit = 0<br />
<br />
Dim range1 As Range<br />
range1 = ActiveSheet.Range("A1")<br />
<br />
Do While range1.Value <> "Not Filled / On Order"<br />
range1 = range1.Offset(1, 0)<br />
Loop<br />
<br />
range1 = range1.Offset(1, 0)<br />
<br />
Do While range1.Value <> "Other"<br />
range1 = range1.Offset(0, 17)<br />
boAmount = boAmount + range1.Value<br />
If range1.Value <> "" Then boUnit = boUnit + 1<br />
range1 = range1.Offset(1, -17)<br />
Loop<br />
<br />
range1 = range1.Offset(0, 17)<br />
'range1.Value = boAmount<br />
<br />
range1 = range1.Offset(1, 0)<br />
Do While range1.Value <> ""<br />
shippedAmount = shippedAmount + range1.Value<br />
If range1.Value <> "" Then shippedUnit = shippedUnit + 1<br />
range1 = range1.Offset(1, 0)<br />
Loop<br />
<br />
'range1.Value = shippedAmount<br />
<br />
'range1.Select<br />
<br />
<br />
Sheets.Add()<br />
Dim range2 As Range<br />
range2 = ActiveSheet.Range("A1")<br />
<br />
range2.Value = "Back Order Amount"<br />
range2 = range2.Offset(0, 1)<br />
range2.Value = boAmount<br />
<br />
range2 = range2.Offset(1, -1)<br />
range2.Value = "Back Order Units"<br />
range2 = range2.Offset(0, 1)<br />
range2.Value = boUnit<br />
<br />
range2 = range2.Offset(1, -1)<br />
range2.Value = "Shipped Amount"<br />
range2 = range2.Offset(0, 1)<br />
range2.Value = shippedAmount<br />
<br />
range2 = range2.Offset(1, -1)<br />
range2.Value = "Shipped Units"<br />
range2 = range2.Offset(0, 1)<br />
range2.Value = shippedUnit<br />
<br />
Columns("A:A").EntireColumn.AutoFit()<br />
Columns("B:B").EntireColumn.AutoFit()<br />
Columns("A:A").Select()<br />
Selection.Font.Bold = True<br />
ActiveSheet.Name = "Totals"<br />
ActiveWorkbook.Save()<br />
<br />
End Sub<br />
<br />
End Module<br />
|
|
|
|
|
The Excel object should be referenced in your project. Try looking up MS Office Interop.
|
|
|
|
|
Hello again
I've a textbox where i write the name of a file or a folder to check
to check a foder I've a function and to check a file I've another function
how to distinct if the user write the name of a foder or a file to tell the programe which function to check
thanks in advance
Assaf
|
|
|
|
|
Using just what the user typed in the TextBox, you can't. How about trying BOTH functions, with proper result handling, and seeing which function says the entered name exists?
|
|
|
|
|
each function give a message tell me the result
but i try to avoud having to message box
if there other way please tell me
Assaf
|
|
|
|
|
It's not a matter of a function giving you what you want. It's your logic that's flawed here. Your methods that check for the existance of a folder or file should just return a Boolean. They shouldn't put up a MessageBox at all.
Think about it. You call both functions with the same name. If they both return false, then the entered name doesn't exist as either a file or a folder. If one of them returns true, then I guess you've found out which it is. If they both return true, you've seriously messed up your checking code in one or both of your methods.
|
|
|
|
|