|
thanks, it works!
Stephan.
|
|
|
|
|
There are at least 3 ways to do what you want:
1. As already mentioned, use ubound. ubound is a vb only feature and is convenient because it returns the upper bound of the array which is usefull for loops.
2. mydata.Length basically returns the count of array items. This available in any language of .net. It is less convenient for loops because you must subtract 1 from it.
3. For Each loop:
For Each str As String In MyData
'Do Something
Next
You don't have to know the array bounds to loop through the items.
|
|
|
|
|
I'm a novice at code writing (newbie is something my kids would call it) and need some advice.
I need to write some code that enables me to access and manipulate data from a database object. This code has to validate the data away from the database. I would personally like to use an object that has methods that read and write to the database and properties that manage validation. This would make life easier when using the properties or field values with other objects. The problem with business objects is the time it takes to create the object.
If I want to run a datagrid based on a collection of business objects it takes too long to create the object collection (for example sales orders). Linking the datagrid to a dataview and using a datatable to hold the values is far quicker. The business objects method appears to provide a better method of creating sales orders without access to the database using a localised copy of any necessary data (part codes, etc).
One other point, the database is provided by a third party and I'm writing an additional interface (this is allowed and part of the software contract) that provides additional facilities. So that the interface isn't restricted by hard coding I have created configuration files that identify table field names, label descriptions, table column headers, table widths, column orders and properties used to create a tab control interface such as top,left,width (for the placement of text boxes) and group properties (used to create different tab pages). I've done this because I'm just a little concerned that if I leave the company they won't be able to change any of the intferface.
I know I can't avoid hard coding validation but the data screens can be configured without hard coding. I currently use a tab deliminated file (so we can use commas in field names or sql commands) but will propbably change to xml as excel is rubbish for tab deliminated (places double quatation marks without asking) and I wan't a columned interface for users to read/write to the configuration files.
What is everyone's thoughts on this. Time to retrieve and refresh data is important. The ability to travel half way around the world and create a 'dummy' sales order to enter into the database is also equally as important.
Any advice would be gratefully appreciated.
Fawxes
An optimist's glass is half full.
A pesimist's glass is half empty.
An engineer goes and gets the right size glass.
|
|
|
|
|
System.IO.IOException: Insufficient system resources exist to complete the requested service.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.__Error.WinIOError()
at System.IO.FileInfo.MoveTo(String destFileName)
at SPC_Polish_Services.CommonFunction.MoveFile(String oldPath, String fileName, String subDir, Int32 fid, String type)
I'm trying to movefile a file in my windows service.
I've no idea at all how to solve this problem..
please help me...thanks~
sayhigh_soon
|
|
|
|
|
We need to see the code that your using to move the file. The error you posted isn't supplying enough information. Also, is the service running under the Local System account, or an account created for this service?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks for your reply.
The service is running under local system account.
<br />
'********************************************************************<br />
' Process: MoveFile<br />
' Input: oldPath, fileName, subDir ['Save'|'Error'], fid, Type ['NEW' | 'UV']<br />
' Output: Move file to destination folder<br />
'********************************************************************<br />
Public Sub MoveFile(ByVal oldPath As String, ByVal fileName As String, ByVal subDir As String, ByVal fid As Integer, ByVal type As String)<br />
Dim Conn As New SqlConnection(strConn)<br />
Dim fi As New FileInfo(oldPath)<br />
Dim targetDir As String = ConfigurationSettings.AppSettings("dirPath" & type).Trim & "\" & subDir<br />
Dim newPath As String = targetDir & "\" & fileName<br />
Dim tblStatusName As String = ConfigurationSettings.AppSettings("tblStatusName" & type).Trim<br />
Dim errorMsg As String<br />
Dim attempt As Integer = 0<br />
<br />
If File.Exists(newPath) Then<br />
'Extra: To ensure delete only normal file (destination folder)<br />
File.SetAttributes(newPath, FileAttributes.Normal)<br />
File.Delete(newPath)<br />
End If<br />
<br />
'Try for another 5 attempts if meet "it is being used by another process" error<br />
Do<br />
Try<br />
'Set the Read-Only file (source folder) to normal file before move to destination folder<br />
If File.Exists(oldPath) Then<br />
File.SetAttributes(oldPath, FileAttributes.Normal)<br />
<br />
'If target folder not exist then create the folder<br />
If Not Directory.Exists(targetDir) Then<br />
Directory.CreateDirectory(targetDir)<br />
End If<br />
fi.MoveTo(newPath)<br />
<br />
'Log<br />
EvtLog("File successfully moved to " & newPath, localhost.EventLogEntryType.Information, 5)<br />
DBLog(logTableName, type, oldPath, "File successfully moved to " & newPath, logName, logSource)<br />
End If<br />
<br />
GoTo final<br />
<br />
Catch ex As Exception<br />
errorMsg = ex.ToString<br />
<br />
If InStr(errorMsg, "it is being used by another process") <> 0 Then<br />
<br />
If attempt <= 5 Then<br />
EvtLog("*** Sub MoveFile Attempt " & attempt & " fail(" & oldPath & "): " & ex.ToString, localhost.EventLogEntryType.Error, 15)<br />
DBLog(logTableName, type, oldPath, "Sub MoveFile Attempt " & attempt & " fail: " & ex.ToString, logName, logSource)<br />
<br />
attempt += 1<br />
<br />
'Wait for 30 seconds before go for another attempt<br />
Thread.CurrentThread.Sleep(30000)<br />
End If<br />
<br />
Else<br />
GoTo email<br />
End If<br />
End Try<br />
Loop While attempt <= 5<br />
.....<br />
.....<br />
.....<br />
End Sub<br />
sayhigh
|
|
|
|
|
A little convoluted, don't you think?
First, strip out all the logging code and get it down to just what is essential for making 5 attempts at moving the file.
Get rid of this line, you never use the object:
Dim Conn As New SqlConnection(strConn)
Rewrite the code and NEVER use "Goto"'s.
Get rid of the "fid" parameter in your method header, you never use it.
Get rid of the "type" parameter in your method header. All you use it for is logging information, which is not an essential part of what this function does.
KEEP IT SIMPLE! Get it down to a working function first, then add the logging code you need.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am getting a similar error. I have a simple windows app that copies a local file to a unc path. The application works fine on 5 out of 6 win2003 servers. on the 6th one it throws an error similar to the one shown above. So far i can't find any setup differences between the servers.
here is the function i have that copies the file. pretty straightforward.
public static string SaveFile(string destinationPath, byte[] file, string fileName, bool overwriteExisting)
{
string returnFileName = fileName;
if (overwriteExisting == true)
{
using (FileStream fStream = new FileStream(destinationPath + @"\" + returnFileName, FileMode.Create, FileAccess.Write))
{
fStream.Write(file, 0, file.GetLength(0));
fStream.Seek(0, SeekOrigin.Begin);
}
}
else
{
using (FileStream fStream = new FileStream(destinationPath + @"\" + returnFileName, FileMode.CreateNew, FileAccess.Write))
{
fStream.Write(file, 0, file.GetLength(0));
fStream.Seek(0, SeekOrigin.Begin);
}
}
return returnFileName;
}
Kirk Quinbar
Zywave, Inc.
|
|
|
|
|
HI Everybody!
I just want to know what is major difference between a Dataset and reordset.
Does recordset object is supported in VB.NET
Please help me in finding the answer
|
|
|
|
|
A recordset is just that, a set of records in a single table. A DataSet can represent multiple tables, with varying records, and relationships between those tables.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hai ,
the major difference is ADO recordset is Connectted DataAccess and a single dimensionsional array to hold datas
in 1d array so if you wanna navigate through data ,u need to use movenext,movelast method,BUt in .net
is disconnected data access ,The datas are stored in datatable in multidimensionsal array like your database table.
so you can navigate the record via simple methods.and dataset is the in memory representation that can hold many tables.
you can make relationship bettween table and dataset is in XSD for so you can send through network without marshelling.
and you can use ADO recordset objects in .Net with the refernce of MsADo.dll files For more info go to MSDN APril 2003
Ishak
Programmer analyst
ITI KSA
|
|
|
|
|
Dear Visual Basic & Access Experts
In my application program, I have a Access (version xp) form that calls a update event handler. In this handler I need to know if the user has clicked on the "Close" button of the form. What VBasic codes do we use to check what action triggers off the the chain of events that lead up to the update event & onwards? In particular I am interested to to check if the triggering event is the clicking of the "Close" button of the form; if so I will then write some code to handle this particular case. I tried to handle this via Close event handler but since it comes after the "Update" event, it does not work.
Please help...Cheers! Michael
|
|
|
|
|
FuzMic wrote:
In this handler I need to know if the user has clicked on the "Close" button of the form.
There is no way to trace back to see what triggered the update. Since the Close event of the form fires AFTER your Update event, you can't set a flag that specifies the form is closing, so there is no way for your code to know the difference, and frankly, in the grand scheme of things, the Update event shouldn't care if the form is closing or not.
Why do you need to change the functionality of the Update on Form Close?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It sounds like you are trying the round-a-bout way of doing things.
Could you do what you want by having separate 'OK' and 'Cancel' buttons? With a cancel button you can prevent the Update, if that's what you're looking to do.
FuzMic wrote:
In particular I am interested to to check if the triggering event is the clicking of the "Close" button of the form
If you just want to know if the close button has been clicked when the Update event occurs, you could define a module-level boolean such as closeClicked initialized to FALSE .
In the Close button's OnClick handler, set closeClicked = TRUE . Then, in your OnUpdate handler, you can check the value of closeClicked to see if the button has been pushed.
Just make sure you set closeClicked = TRUE before the docmd.close acForm, me.name command.
I wouldn't go so far as to call this method 'sloppy', but I would think there should be a more graceful way of accomplishing your goal.
|
|
|
|
|
Dear Mike the Red from Fuzzy Mike
Perhaps my message was not clear; I am not referring to a Close "Command" button that is placed on a form. I am referring to the Form Close button that comes inherent with the form on top right hand corner; in which case, how can a boolean var be flagged on clicking since there is no such event handler within the form to set it up ... UNLESS ... it is via the Window OS???.
Come what say u; Thanks & Cheers!.
Dear Dave Kreskowiak
You wrote: Why do you need to change the functionality of the Update on Form
Close?
I am using the Update event handler to do various checks such as check for duplicate, empty fields, etc. Thus if a user click on the Form Close, the form will go into the update event if the form is dirtied. At this point if the test failed, a message tells user the option to Undo or to make corrections. However since the user want to close the form, I must drop the correction option and change the message.
By the way how do Window OS handle a form close event?
Thanks & Cheers!
|
|
|
|
|
I need to read values from an excel spreadsheet into a string array in VB.NET.
I can read the cells with no problems if I take the values into single dimensional variables, but I get an error when I try to read into an array.
The code fragment is:
Dim filename As String
filename = "c:\pass\userlist.csv"
Dim intRows As Integer
Dim fqn() as string
Dim r, i As Integer
' Open the Workbook in excel
Dim xlApp As Excel.Application
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlApp.Visible = False
Dim xlWB As Excel.Workbook
Dim xls As Excel.Worksheet
xlWB = CType(xlApp.Workbooks.Open(filename), Excel.Workbook)
xls = CType(xlWB.Worksheets(1), Excel.Worksheet)
intRows = xls.UsedRange.Rows.Count
num = intRows - 1
' Scroll through all the rows and columns retrieving values.
i = 1
For i = 0 To num
fqn(i) = CType(xls.Cells(r, 1), Excel.Range).Text
Next
xlWB.Close(False)
xlApp.Quit()
xls = Nothing
xlWB = Nothing
xlApp = Nothing
The error generated is:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Exception from HRESULT: 0x800A03EC.
I have added the Excel library reference (11.0)
Any help would be appreciated
Greg S
|
|
|
|
|
I am trying to display nicely formatted text (as in RTF)
on a graphical background.
The standard RichTextBox control doesn't allow transparency,
so I could overlay a graphics, not does it allow me to set
a background image.
Could anybody tell me how I could get either of these to work,
or alternatively if there is a way to draw the formatted text
from a RichTextBox control on a picture or graphic?
Thanks,
Tom Verkaaik
|
|
|
|
|
I need to connect a scanner(hardware device) programmatically to my vb.net applicaion.The cloth or paper that is being scanned with the scanner should directly come in the picture box in vb.net.Can anyone please help me with it? its very important.If you have an answer then please mail me at avanti_dharkar@rediffmail.com.
|
|
|
|
|
You can use the ImgScan.ocx.
It exists from win 95 to windows 2000. Windows xp doesn't supply this control.
Then you can use its events to direct the scanned image to the picture box.
You can connect any ISIS or Twain scanners to it.
|
|
|
|
|
Thanks, i will try using this
|
|
|
|
|
OK this one has me baffled I just got done writing this program, and I only had a few typos corrected them. The program now starts up and run just fine, but it does not play the wav sounds. I have a textbox and two buttons, btnbrowse and btnplay I'm supposed to be able to browse through my hard drive, find a wav sound and then play it, could someone help me with this please. Thank you
----------------------------------------------------------------------------
Option Strict Off
Option Explicit On
Module modauto
Sub LoadFile(ByRef inFile As String)
Dim hmem As Integer
Dim mmckinfoparentIn As MMCKINFO
Dim mmckinfosubchunkIn As MMCKINFO
Dim hmmioIn As Integer
Dim mmioinf As mmioinfo
mmioinf.adwInfo = Space(4)
hmmioIn = mmioOpen(inFile, mmioinf, MMIO_READ)
If hmmioIn = 0 Then Exit Sub
mmioDescendparent(hmmioIn, mmckinfoparentIn, 0, MMIO_FINDRIFF)
mmckinfosubchunkIn.CKID = mmioStringToFOURCC("fmt", 0)
mmioDescend(hmmioIn, mmckinfosubchunkIn, mmckinfoparentIn, MMIO_FINDCHUNK)
mmioReadFormat(hmmioIn, format_wave, Len(format_wave))
mmioAscend(hmmioIn, mmckinfosubchunkIn, 0)
mmckinfosubchunkIn.CKID = mmioStringToFOURCC("data", 0)
mmioDescend(hmmioIn, mmckinfosubchunkIn, mmckinfoparentIn, MMIO_FINDCHUNK)
GlobalLock(hmem)
hmem = GlobalAlloc(&H40S, mmckinfosubchunkIn.cksize)
bufferin = GlobalFree(hmem)
mmioRead(hmmioIn, bufferin, mmckinfosubchunkIn.cksize)
numSamples = mmckinfosubchunkIn.cksize / format_wave.nBlockAlign
mmioClose(hmmioIn, 0)
End Sub
Sub play(ByVal soundcard As Short)
Dim rc As Integer
Dim lFlags As Integer
lFlags = Callback_Function
If soundcard <> -1 Then lFlags = lFlags Or WAVE_MAPPED
rc = waveOutOpen(hwaveout, soundcard, format_wave, 0, 0, lFlags)
If (rc <> 0) Then Exit Sub
outhdr.lpData = bufferin
outhdr.dwBufferLenght = numsamples * format_wave.nBlockAlign
outhdr.dwFlags = 0
outhdr.dwLoops = 0
waveOutPrepareHeader(hwaveout, outhdr, Len(outhdr))
waveOutWrite(hwaveout, outhdr, Len(outhdr))
End Sub
Public whdr As WAVEHDR
Public format_wave As WAVEFORMAT
Public outhdr As WAVEHDR
Public bufferin As Integer
Public numsamples As Integer
Public hwaveout As Integer
Public Const MMIO_Read As Short = &H0S
Public Const Callback_Function As Integer = &H30000
Public Const WAVE_MAPPED As Short = &H4S
Public Const MMIO_FINDCHUNK As Short = &H10S
Public Const MMIO_FINDRIFF As Short = &H20S
Structure MMCKINFO
Dim CKID As Integer
Dim cksize As Integer
Dim fcctype As Integer
Dim dwdataoffset As Integer
Dim dwflags As Integer
End Structure
Structure mmioinfo
Dim dwflags As Integer
Dim fccIOproc As Integer
Dim pIOProc As Integer
Dim wErrorRet As Integer
Dim htask As Integer
Dim cchBuffer As Integer
Dim pchBuffer As String
Dim pchnext As String
Dim pchEndRead As String
Dim pchEndWrite As String
Dim lBufOffset As Integer
Dim lDiskOffset As Integer
Dim adwInfo As String
Dim dwReserved1 As Integer
Dim dwReserved2 As Integer
Dim hmmio As Integer
End Structure
Structure WAVEFORMAT
Dim wFormattag As Short
Dim nChannels As Short
Dim nSamplespersec As Integer
Dim nAvgBytespersec As Integer
Dim nBlockAlign As Short
Dim wBitsPerSample As Short
Dim cbSize As Short
End Structure
Structure WAVEHDR
Dim lpData As Integer
Dim dwBufferLenght As Integer
Dim dwBytesRecorded As Integer
Dim dwUser As Integer
Dim dwFlags As Integer
Dim dwLoops As Integer
Dim lpNext As Integer
Dim Reserved As Integer
End Structure
Declare Function waveOutWrite Lib "winmm.dll" (ByVal hWaveout As Integer, ByRef lpWaveoutHdr As WAVEHDR, ByVal uSize As Integer) As Integer
Declare Function waveOutPrepareHeader Lib "winmm.dll" (ByVal hWavein As Integer, ByRef lpWaveInHdr As WAVEHDR, ByVal uSize As Integer) As Integer
Declare Function mmioRead Lib "winmm.dll" (ByVal hmmio As Integer, ByVal pch As Integer, ByVal cch As Integer) As Integer
Declare Function waveOutOpen Lib "winmm.dll" (ByRef lphWaveIn As Integer, ByVal uDeviceID As Integer, ByRef lpFormat As WAVEFORMAT, ByVal dwCALLBACK As Integer, ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Integer, ByVal dwBytes As Integer) As Integer
Declare Function GlobalLock Lib "kernel32" (ByVal hmem As Integer) As Integer
Declare Function mmioAscend Lib "winmm.dll" (ByVal hmmio As Integer, ByRef lpck As MMCKINFO, ByVal uFlags As Integer) As Integer
Declare Function GlobalFree Lib "kernel32" (ByVal hmem As Integer) As Integer
Declare Function mmioOpen Lib "winmm.dll" Alias "mmioOpenA" (ByVal szFileName As String, ByRef lpmmioinfo As mmioinfo, ByVal dwOpenFlags As Integer) As Integer
Declare Function mmioDescendparent Lib "winmm.dll" Alias "mmioDescend" (ByVal hmmio As Integer, ByRef lpck As MMCKINFO, ByVal x As Integer, ByVal uFlags As Integer) As Integer
Declare Function mmioReadFormat Lib "winmm.dll" Alias "mmioRead" (ByVal hmmio As Integer, ByRef pch As WAVEFORMAT, ByVal cch As Integer) As Integer
Declare Function mmioClose Lib "winmm.dll" (ByVal hmmio As Integer, ByVal uFlags As Integer) As Integer
Declare Function mmioStringToFOURCC Lib "winmm.dll" Alias "mmioStringToFOURCCA" (ByVal sz As String, ByVal uFlags As Integer) As Integer
Declare Function mmioDescend Lib "winmm.dll" (ByVal hmmio As Integer, ByRef lpck As MMCKINFO, ByRef lpckparent As MMCKINFO, ByVal uFlags As Integer) As Integer
End Module
|
|
|
|
|
You've got WAY too much code for this. How about getting some pointers from How To Play a Waveform (.WAV) Sound File in Visual Basic[^] on MSDN. It's written for VB4, VB5, and VB6, but is easily convertable to VB.NET code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, I have the following two procedure:
Private Sub btnEvalGuide_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnEvalGuide.Click
' the code work here.
' ...
End Sub
Private Sub btnUseDtGl_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnIntVuDmExp.Click
' the code work here.
' ...
' ...
' need to call btnEvalGuide.Click
' but i don't know how to do it.
End Sub
When the code in btnIntVuDmExp.Click run it do it task and finally i need it to call to btnEvalGuide.Click . But i don't know how to do it. Can anyone give me a suggestion???
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
it seems that btnEvalGuide and btnIntVuDmExp both are buttons .u can can use
call btnEvalGuide_Click(sender,e)
that's all.
good luck
|
|
|
|
|
Thank you very much for your comment. I will try to do that, but if it is not working I will do it in a separate procedure then make a call to that procedure instead.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|