G_Waddell 131 Posting Whiz in Training

Hi

This isn't really a Vb.net question...

A tip for you though is to open the sql managment console, point it at your Database and run the following in a query window:

EXEC spGetAdjustmentDetail @AdjustmentId=####

(### = a value for adjustment ID)

It will output the results to the window for you.

If you're Using SQL Express or MSDE you have to get a copy of the management studio from another edition (developer, enterprise etc) although you may be able to down load it - I'm not too sure

G_Waddell 131 Posting Whiz in Training

Hi

Can you give us some sample code?

It really depends on which type of file you are printing - if it is a word, excel etc file then you can easily use the built in print functions to print the page. Acrobat has it's own internals too.

The last printing project I worked on then if it was plain text or RTF I opened it in Word.

G_Waddell 131 Posting Whiz in Training
G_Waddell 131 Posting Whiz in Training

Hi
To Refer to the OpenFileDialog you would use something like this:

dim MyDialog as New OpenFileDialog

You should be able to find out how to use the dialog here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx
To actually open, edit and save the file then you should use System.IO Namespace if you look it up on Google you'll see lots of examples of using it.

G_Waddell 131 Posting Whiz in Training

hi am new here and in vb.net
and i've been trying to display outputs form an array but the message box appears empty with nothing in it ..
here is the code :

Dim r As Random = New Random()

For i = 1 To dept_no


For j = 0 To dept(i).GetUpperBound(0) - 1

dept(i)(j) = r.Next(300, 1000)
output &= dept(i)(j) & " "


Next
output &= vbCrLf


Next
MessageBox.Show("salaries are" & vbTab & output)

Hi

Where are you defining the size of your Array?

Also parse through your code in debugg mode and add a watch to the output string does the value change with each loop and is it increasing?

G_Waddell 131 Posting Whiz in Training

I should have checked my page load event.....

G_Waddell 131 Posting Whiz in Training

Hi Folks,

I wonder if anyone knows what is happening here because I'm very confused...

I have some nested repeater that I'm using to display a list of Categories, projects and tasks on my ASP.net site written in VB.net

i.e.
Repeater 1 Category
Repeater 2 Project
Repeater 3 Task

In the task items, I have an edit feature where one placeholder is made visible and the other is closed.

The issue happens after my users have edited the values and hit my save button I can no longer access the values they have inputted in the edit fields even though if I do a view source on the page I can see the values and the Client Id's match up in the code step through.

<asp:Repeater Id=Category runat ="server">
<ItemTemplate>
<table border=0 cellpadding =0 cellspacing=0>
  <tr>
      <td><%# Eval("CategoryName")%></td>
  </tr>
  <asp:Repeater id="Project" runat="server">
  <ItemTemplate>
   <tr>
     <td>
        <table border=0 cellpadding =0 cellspacing=0>
        <tr>
           <td></td>
           <td><asp:HiddenField id="ProjectID" value='<%#Eval("ProjectID")%>' /><%# Eval("ProjectName")%></td>
           </td>
         </tr> 
         <tr>
            <td></td>
            <td>
               <table border="0" Cellpadding="0" CellSpacing="0>
                <THead>
                    <th>Task</th>
                    <th>Status</th>
                    <th>Due</th>
                </THead>
                <TBody>
                 <asp:Repeater id="Tasks">
                 <ItemTemplate>
                 <asp:HiddenField id="TaskID" Value='<%# Eval("TaskID")%>' />
                 <asp:HiddenField id="StatusCode" Value='<%# Eval("StatusCode")%>' />
                 <asp:PlaceHolder id="Task">
                 <tr>
                     <td><asp:LinkButton id="TaskLnk" OnClick="EditMe" Text='<#% Eval("TaskName")%>' /></td>
		     <td><asp:LinkButton id="StatusLnk" OnClick="EditMe" Text='<#% Eval("Status")%>' /></td>
		     <td><asp:LinkButton id="DateLnk" OnClick="EditMe" Text='<#% Eval("DueDate")%>' /></td>
		     <td>&nbsp;</td>
                 </tr> 
                 </asp:Placeholder >
		<asp:PlaceHolder id="EditTask" Visible="False>
                 <tr>
                     <td><asp:Textbox id="txtTaskEdit" /></td>
		     <td><asp:DropDownList id="dlStatus" /></td>
		     <td><asp:LinkButton id="EditDateLnk" OnClick="EditDate" Text='<#% Eval("DueDate")%>' /></td>
		     <td>
                         <table border="0">
                         <tr>
                           <td><asp:LinkButton id="SaveLnk" OnClick="saveMe" Text="Save" /></td>
			   <td>&nbsp;</td>
                           <td><asp:LinkButton id="CancelLnk" …
G_Waddell 131 Posting Whiz in Training

Investigating the Google issue. In the meantime, you can go into a category. Then click the title of the category (where it says click to expand) to bring up a menu of subforums.

Thanks!

I do actually like the site, although the main thing I enjoy is the fact that the folks out there really do care and lend a hand -it is a good community of people that you have built up on the site - well done.

G_Waddell 131 Posting Whiz in Training

The [code] button spelled out, watermark in the editor window, and Code Explanation page are all coming back. The "New" button in thread listings is also coming back. So is solved threads and reputation within posts.

Hi,
Can you do something about the dropdown menus hiding behind the google ads in IE8? I can't navigate the site properly :(

G_Waddell 131 Posting Whiz in Training

Hi,

I'm having an issue with IE 8 and the new design I can't access most of the forums because dropdown menus are appearing behind the Google ads along the top.

I tried to go to the category page and navigate from there but unless there is a recent post from the forum I want I'm stuck....

G_Waddell 131 Posting Whiz in Training

Have a look,

Dim dt As New DataTable
        dt.Columns.Add("No", GetType(Integer))
        dt.Columns.Add("Name")

        dt.PrimaryKey = New DataColumn() {dt.Columns(0)}

Thanks! thats did the job...

G_Waddell 131 Posting Whiz in Training

Hi,

I have an issue involving retrieving a set of child rows in a dataset.

I have populated a dataset with three tables Categories, Projects and Tasks. In the dataset relations I have set up a relationship between Categories and Projects and between Projects and Tasks.

Private Sub Defaults_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
....
with myDset
   .tables(0).TableName ="Categories"
   .tables(0).Columns("CategoryID").Unique = True
   .tables(1).TableName ="Projects"
   .tables(1).Columns("ProjectCode").Unique = True
   .tables(2).TableName ="Tasks"
   .tables(2).Columns("TaskCode").Unique = True
  with .relations
      .Add("ProjectCategory", myDSet.Tables("Categories").Columns("CategoryID"), myDSet.Tables("Projects").Columns("CategoryID"))
      .Add("ProjectTasks", myDSet.Tables("Projects").Columns("ProjectCode"), myDSet.Tables("Tasks").Columns("ProjectCode"))
  end with
end with
.....
end sub

This all works fine when I debug.

Using this dataset I wish to populate some comboboxes to allow the user to select a Category then a Project and get the list of
tasks in a listbox.

So I populate the category combo with no issue. However when I try and retrieve the selected row of the table I get an error stating that no primary key has been set.

Private Sub cbProjCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbProjCat.SelectedIndexChanged
....
dim Category as Dataitem 'custom class allows an id and string value to be passed into combobox

'Which Category has been selected
 Category = cbProjCat.SelectedItem
 'What is the ID?
 CategoryID = Category.ID
'Get this row in the Categories table in the Dataset 
 CategoryRow = myDSet.Tables("Categories").Rows.Find(CategoryID)
...
end sub

I tried setting the primarykey on the datatables like so but I get an error about it not accepting 1 dimensional arrays...

G_Waddell 131 Posting Whiz in Training

Hi,

It sounds fine for a starter project, it has a real life application and is in an area of interest most people can relate to.

What are you going to use to search on? Are you intending to use a backend Database? If so you should only use enough samples (say one or two genres of music with a couple of artists in each) or else you could fall into the trap of spending most of your project populating the the database!!

G_Waddell 131 Posting Whiz in Training

Open the prescribed text on VB programming for whatever course you are on at chapter one

G_Waddell 131 Posting Whiz in Training

Hi,
I don't see in your code where you INSERT a record....
You only SELECT records and UPDATE an existing record (if there are any)

Also I'm not sure I follow exactly what it is you are doing.

I see that you get a username value from a list box called teachers
and try to find matching records - if you find none, you get a username value from another list box called listBox and update matching records to type admin. I'm just trying to understand why?

G_Waddell 131 Posting Whiz in Training

Hi
You would need to hold your values in a string or some other variable that you can then put into a message box at the end of your loop. e.g.

dim ReOrderItems as String

For increment = 0 To MaxRows - 1

quantity = KiwicyclesDataSet.Stock_Control.Rows(increment).Item("Quantity")
reorderlevel = KiwicyclesDataSet.Stock_Control.Rows(increment).Item("Re-Order Level")
name = KiwicyclesDataSet.Stock_Control.Rows(increment).Item("Model")

If reorderlevel >= quantity Then
MsgBox("Need to re-order" & name)
ReOrderItems = ReOrderItems &name &", "
Else
MsgBox("Stock is OK")
End If

Next
msgbox("The following items need to be restocked:" &vbcrlf  &ReOrderItems)
G_Waddell 131 Posting Whiz in Training

The problem turned out not to be on the remote pc but rather in the way my SQL server was set up....... DOH!

G_Waddell 131 Posting Whiz in Training

Hi All,

I've published a app using Clickonce Deployment for use on our LAN (so I've set it to online only for ease of updates etc)

When I run the setup on my own machine, the app installs and runs with no issue however when I run the setup on my test machine, The program installs and opens but I get an error while running it about an object reference not being set. The application is falling over where a user logs into the system and the app makes a call to a SQL database using SQL native client.

I've looked at the references and System.data is there I've also checked that System.Data and Microsoft.SQLServer name spaces are included.

I next made sure the application was set to a full trust application under the security for ClickOnce deployment. I then set all the application files to Include and made sure the .net framework 3.5SP1 was checked under the prerequiste files and download prerequistes from vendors web site was checked.

But I still didn't get it to work on the test machine I noticed that SQL native Client had not installed on the test machine so I ran the sqlncli.msi off of my SQL 2005 server disk to install it manually but I still can't get it to run.

I know I'm probably missing something but I've never deployed with ClickOnce before so I'm not 100% sure of it.

Here is the code where …

G_Waddell 131 Posting Whiz in Training

That's great it looks like what I'm looking for, I had been trying launching the DOS command as a process, passing in net share as an arguement then trying to read back the output so I could compare to the returned path and hence change back to the UNC - yuck!

I spoke too soon, I could not stop it giving me back the local path....

So.....

I found some code on line that allows me to parse through the network structure returning objects using the mpr.dll so i'll play around with that so I get back all the network shares and their local paths on the machine and then compare to the path from the dialog.

G_Waddell 131 Posting Whiz in Training

Take a look at this lib - http://www.codeplex.com/DotNetZip/SourceControl/changeset/view/29499#432677

That's great it looks like what I'm looking for, I had been trying launching the DOS command as a process, passing in net share as an arguement then trying to read back the output so I could compare to the returned path and hence change back to the UNC - yuck!

G_Waddell 131 Posting Whiz in Training

Hi All,

I hope someone out there can help with this.

I'm writing an app where a user selects a folder on the network for a job to deposit output into.

The person setting up the job will not necessarily be the same person who runs the job and that the job will not be ran on the same machine so I need to keep the path in UNC format.

I can get the user to "see" the network when the FolderBrowserDialog runs by pointing the route folder at the desktop folder.

The issue is that if the network share is local even though the user has selected the folder through the network folders it returns the local path!! Which of course means that when the job is run on the other machine it can not find the folder specified.

E.g. The user on machine1 selects the network share \\machine1\jobs\myjob but the dialog returns C:\work\2010Jobs\Client\jobs\myjob. machine2 then runs the job and looks for C:\work\2010Jobs\Client\jobs\myjob and can not find it then throws an error.

As you can see from the above example I can't just replace c:\ with the local machine name as the share may not be in the root of the drive.

I did think about parsing the text and changing it to \\machine1\c$\work\2010Jobs\Client\jobs\myjob but this would mean I'd have to allow all the users to have admin access to our servers which is a non starter.

Does anyone know …

G_Waddell 131 Posting Whiz in Training

All,
Currently we have macros built so my guy just highlights the excel cells (each one represents an hour of the day) and hits a key to color the cells red (green is default).

I'd open up those macros and expand on them to build one that parses through the cells in Excel that you wish to evaluate and then colour according to your criteria. - being as they're Excel macros they're probably written in VBA.

You can work through Excel cells by specifying them like this mysheet.Cell(y,x) - note the row comes first in excel then the column or you can use ranges.

Alternatively, if you run the record macro feature in Excel and manually carry out the steps i.e. select the cell turn it red move on to next cell turn it red then when you stop recording the code to turn one cell red and then move to the next and turn it red will be written and you can expand on it to include your conditionals and other variables.

G_Waddell 131 Posting Whiz in Training

Hi all,

I'm writing an application that imports and tidy up address data into a cleaned, deduped excel workbook ordered in rows with each column as an address field.

One of the issues I've ran into is that we sometimes get a workbook where the multiple address fields are held in a single cell with line breaks.

I've written code to extract all of this data out of the excel sheet in to a dataset with each sheet as a table and the address fields contained within.

I now want to create a new Excel workbook from this data with the address fields in Row and columns the problem I have is I can Open/create the Workbook but when I try to insert a new Sheet (Table) I get an error saying the Workbook is read only....

Private Sub MakeSimpleXL(ByRef DsTemp As DataSet)
        Dim dsTable As Data.DataTable
        Dim tblName As String
        Dim dsRow As Data.DataRow
        Dim sFile, xlConn As String
        Dim intItem, intRow, intTable As Integer
        Dim sQry, sFields, sValues As String 
        Dim mCommand As OdbcCommand = OdbcCommand
        Dim OConn as OdbcConnection

        sFile = Replace(xlDest, ".xl", "_src.xl")
        If File.Exists(sFile) Then File.Delete(sFile)
        xlConn = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & sFile & ";DefaultDir=c:\mypath;"
        OConn = new OdbcConnection(xlConn)
       OConn.open ' excel sheet is created....
        For Each dsTable In DsTemp.Tables
            'creation of new worksheet in workbook
            intTable = intTable + 1
            If dsTable.TableName Is Nothing Then
                tblName = "Page " & intTable
            ElseIf dsTable.TableName = "" Then
                tblName = "Page " & intTable
            Else …
G_Waddell 131 Posting Whiz in Training

Hi all,

I'm writing an application that imports and tidy up address data into a cleaned, deduped excel workbook ordered in rows with each column as an address field.

One of the issues I've ran into is that we sometimes get a workbook where the multiple address fields are held in a single cell with line breaks.

I've written code to extract all of this data out of the excel sheet in to a dataset with each sheet as a table and the address fields contained within.

I now want to create a new Excel workbook from this data with the address fields in Row and columns the problem I have is I can Open/create the Workbook but when I try to insert a new Sheet (Table) I get an error saying the Workbook is read only....

Private Sub MakeSimpleXL(ByRef DsTemp As DataSet)
        Dim dsTable As Data.DataTable
        Dim tblName As String
        Dim dsRow As Data.DataRow
        Dim sFile, xlConn As String
        Dim intItem, intRow, intTable As Integer
        Dim sQry, sFields, sValues As String 
        Dim mCommand As OdbcCommand = OdbcCommand
        Dim OConn as OdbcConnection

        sFile = Replace(xlDest, ".xl", "_src.xl")
        If File.Exists(sFile) Then File.Delete(sFile)
        xlConn = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & sFile & ";DefaultDir=c:\mypath;"
        OConn = new OdbcConnection(xlConn)
       OConn.open ' excel sheet is created....
        For Each dsTable In DsTemp.Tables
            'creation of new worksheet in workbook
            intTable = intTable + 1
            If dsTable.TableName Is Nothing Then
                tblName = "Page " & intTable
            ElseIf dsTable.TableName = "" Then
                tblName = …
G_Waddell 131 Posting Whiz in Training

Hey,

i'm trying to have 2 browse file dialog boxes, one that allows you to select a file from a folder, and the other folder should allow you to chose the location to copy the file to.

Thanks

Hi You want to use an OpenFileDialog box for the Selection and a SaveFileDialog box for the destination. Then you copy the source file to the destination:

Private Sub CopyFile()
dim sSource as string
dim sDestination as string
dim diaSrc as new OpenFileDialog
'set up open file
with diaSrc
     .Title = "Browse to Document"
      .InitialDirectory = "C:\"
      .Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
      .RestoreDirectory = True
end with

if diaSrc.showdialog = Windows.Forms.DialogResult.OK Then
   sSource = diaSrc.fileName
end if
'do the same with the destination on a savefiledialog....
'......

if file.exists(sDestination) Then 
   file.delete(sDestination)
end if
file.copy(sSource, sDestination)
end sub
G_Waddell 131 Posting Whiz in Training

I've given up and no longer allow the users to specify OMR output with PDF documents. :(

I even tried encapsulating the whole PDF printing in a class object and setting up dispose methods but the same document remained open. :-O

G_Waddell 131 Posting Whiz in Training

Hi All,

I'm writing an app that prints of batches of documents to clients for posting. The printer uses OMR to collate and fold the documents into envelopes automatically.

The document inputs will either be Word or Adobe Acrobat. I have routines to print off each document type while adding OMR on the fly.

The issue I have is that when the routine for PDF is run, the Adobe file is not closing properly. So when the next clients batch is being printed, there is an error saying that the document is locked by another user or process.

I'm using the Acrobat 7 reference library and have Acrobat 7 installed on my machine (full blown product, not reader,)

I'm closing the PDDocument, the AVDocument and the application in the code and I've even wrote a routine to kill the process to no avail.

Basically my code copies the source file into a new file.
It then parses through the pages building a string called strOMR in the format OMR_?_SeqNO for each page.
Where SeqNo is a number between 0 and 7 relating to the position of the page in the overall batch of documents. If on the last page of the last document, then ? is given the value I (for insert) else S.

I now look in a template of precreated PDF Annots containing the necessary OMR markup and copy the one thats title matches the string I have built …

G_Waddell 131 Posting Whiz in Training

I'm using mysql database..I have forms setup main form has datagrid..you can add to this datagrid and save to datbase with my add form and it works fine. I can delete from the datagrid and it works fine...when I select an account to edit is when I have my issue...form edit brings up the selected account but when I save my changes it doesn't save to the selected account it changes my first account in the database...Help...here is a sample of my code
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
' 'Save changes to database and exit
Dim intResponse As String
intResponse = MsgBox("Do you want to SAVE Changes to this record?", vbOKCancel, "Save?")
If intResponse = vbOK Then

PbCustomerDS.customer(0).Address_Line1 = Address_Line1TextBox.Text
PbCustomerDS.customer(0).Location = LocationTextBox.Text
PbCustomerDS.customer(0).Attention = AttentionTextBox.Text
PbCustomerDS.customer(0).City = CityTextBox.Text
PbCustomerDS.customer(0).State = StateTextBox.Text
PbCustomerDS.customer(0).Zip = ZipTextBox.Text
PbCustomerDS.customer(0).Phone = PhoneMaskedTextBox.Text
PbCustomerDS.customer(0).Bill_To = Bill_ToTextBox.Text
PbCustomerDS.customer(0).Attention_2 = Attention_2TextBox.Text
PbCustomerDS.customer(0).B_address = B_addressTextBox.Text
PbCustomerDS.customer(0).B_City = (B_CityTextBox.Text)
PbCustomerDS.customer(0).B_State = B_StateTextBox.Text
PbCustomerDS.customer(0).B_Zip = B_ZipTextBox.Text
PbCustomerDS.customer(0).B_Phone = B_PhoneMaskedTextBox.Text
PbCustomerDS.customer(0).Comments = CommentsTextBox.Text
PbCustomerDS.customer(0).Updated = UpdatedLabel1.Text

Me.Validate()
Me.CustomerBindingSource.DataSource.GetType()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(PbCustomerDS)
Me.TableAdapterManager.UpdateAll(PbCustomerDS)

Me.Close()
End If
If vbCancel Then
Exit Sub
End If

End Sub

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

can someone please help me with my issue?

Well the reason you are getting the first record changing is because you've hardcoded that the routine will change the first record i.e. the zero index record on the data grid.....

Instead of using

PbCustomerDS.Customer(0).

you need to identify the index of the currently selected row and pass it …

G_Waddell 131 Posting Whiz in Training

Hi Guys,

Well after a bit of poking about and stepping through things I was able to solve both issues:

Error message was caused by my own housekeeping:

If Not wdDoc Is Nothing Then           
 wdDoc.Close(False)           'error caused here document must already be closed but still exists -  took the line out and no error
 wdDoc = Nothing        End If

"Silent Print" resolved by setting destination to new document and then printng the Active document:

......
With oWord.ActiveDocument.MailMerge            
    .Destination = WdMailMergeDestination.wdSendToNewDocument            
   .MailAsAttachment = False            
   .MailAddressFieldName = ""            
   .MailSubject = ""            
   .SuppressBlankLines = True            
  With .DataSource                
   .FirstRecord = WdMailMergeDefaultRecord.wdDefaultFirstRecord                
   .LastRecord = WdMailMergeDefaultRecord.wdDefaultLastRecord            
  End With            
  .Execute(Pause:=True)        
End With
oWord.ActiveDocument.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, Item:=WdPrintOutItem.wdPrintDocumentContent, Copies:=1)

.........
G_Waddell 131 Posting Whiz in Training

And this has what to do with Vb.net exactly?

G_Waddell 131 Posting Whiz in Training

Hi
Try this:

dim dtTable as Datatable
dim drRow as DataRow
dim intRecord as integer
'assume you populated the table etc

for intRecord = 0 to dtTable.Rows.count -1
drRow = dtTable.Rows(intRecord)
myCombox.Items.Add(New DataItem(drRow(0).Tostring, drRow(1).ToString)
next
G_Waddell 131 Posting Whiz in Training

Hi All,

In my VB.Net app, I want to read in a load of addresses from a database and then use word to create address labels on an Avery template L7163 which is then printed to the printer.

However, I have two issues:
1. Before word prints, I'm asked to select the printer etc. not exactly the nice automated application I was looking for.

2. Even though I get a nice printed out doc I was looking for, I also get a nasty looking error at the end which "loops" until I close my app

-2147417848: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x800010108(RPC_E_DISCONNECTED))

Here is my code:

Dim oWord As New Word.Application  'hook into word
        Dim wdDoc, wdDoc2 As Word.Document ' documents in word
        Dim wdAutoText As Word.AutoTextEntry ' auto text for word
        Dim dtAddresses As DataTable 
        Dim drAddress As DataRow
        Dim intAddress As Integer = 0
        Dim txtAddress As StreamWriter
        Dim strAddressRow As String
        Dim frmLabelTray As New frmLabelTray 'dialog that allows user to select tray type
        Dim wdPrinterType As WdPaperTray 'Word Tray type
        Dim diaResult As DialogResult 

On Error GoTo ErrHandler
dtAddresses = objDb.GETAddressListForBatch(gintBatchNo)
 'pulls back addresses in datatable
 If dtAddresses Is Nothing Then
            MsgBox("Unable to print labels, no address records were found", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Unable to Print Labels")
            Resume OUT
        Else
            If dtAddresses.Rows.Count = 0 Then
                MsgBox("Unable to print labels, no address records were found", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Unable to Print Labels")
                Resume OUT
            End If …
G_Waddell 131 Posting Whiz in Training

Hi

I've written a printing application which is working perfectly when I debugg and step through but does not print anything when running a debugg with no breaks / step through.

I suspect I need to use something like Do Events to get the application to print out. However when I type it in, Visual studio 2008 doesn't seam to recognise it. I did find the

System.Threading.Thread.Sleep

Should I be using this instead? and could anyone give me an example of how to use it?
i.e should I be doing :

'printing to word....
oDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, Item:=WdPrintOutItem.wdPrintDocumentContent, Copies:=1)
System.Threading.Thread.Sleep(10)

OR

System.Threading.Thread.Sleep(10)
oDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, Item:=WdPrintOutItem.wdPrintDocumentContent, Copies:=1)

Thanks in advance

Got it working now.....

'printing to word....
oDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, Item:=WdPrintOutItem.wdPrintDocumentContent, Copies:=1)
System.Threading.Thread.Sleep(10)
G_Waddell 131 Posting Whiz in Training

Hi

I've written a printing application which is working perfectly when I debugg and step through but does not print anything when running a debugg with no breaks / step through.

I suspect I need to use something like Do Events to get the application to print out. However when I type it in, Visual studio 2008 doesn't seam to recognise it. I did find the

System.Threading.Thread.Sleep

Should I be using this instead? and could anyone give me an example of how to use it?
i.e should I be doing :

'printing to word....
oDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, Item:=WdPrintOutItem.wdPrintDocumentContent, Copies:=1)
System.Threading.Thread.Sleep(10)

OR

System.Threading.Thread.Sleep(10)
oDoc.PrintOut(Range:=WdPrintOutRange.wdPrintAllDocument, Item:=WdPrintOutItem.wdPrintDocumentContent, Copies:=1)

Thanks in advance

G_Waddell 131 Posting Whiz in Training

Hi

I need to insert some data from Text boxes in an aspx page into an Access DB but I keep getting a Data type mismatch in criteria expression error.

The problem is the Double which I think I have converted correctly. All the other fields are OK as strings but the value from the Grade TextBox needs to go into a Number field in the Access DB that has been set to Double. Here's my code

Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click

        Dim g As Double
        Dim st As String

        st = Grade.Text.Trim
        g = CDbl(st)


        Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
                                        & Server.MapPath("Test.mdb") & ";"
        Dim MySQL As String = "INSERT INTO tblPerson " & _
           "(Name, EMail, Webpage, Comments, Age, Birth, Grade) VALUES " & _
           "('" & Name.Text & "','" & Email.Text & "','" _
           & Webpage.Text & "','" & Comments.Text & "','" _
           & Age.Text & "','" & Birth.Text & "'," & g & ")"

        Dim MyConn As New Data.OleDb.OleDbConnection(strConn)
        Dim cmd As New Data.OleDb.OleDbCommand(MySQL, MyConn)
        MyConn.Open()
        cmd.ExecuteNonQuery()
        MyConn.Close()
        Response.Redirect("GuestBook.aspx")
    End Sub

The code works perfectly without the inclusion of Grade but generates the error when I include Grade.

Thanks
ViRiPuff

Try using the QBE in Access to build a SQL string to insert the values and then use that string to form the SQL your passing in. It will show you how Access passes in a double or if that still doesn't work get msgbox to …

G_Waddell 131 Posting Whiz in Training

Hi I figured it out myself:

Code for Populating combobox:

Dim pkSource As Printing.PaperSource
        Dim strPrinter As String
        Dim printDoc As New Printing.PrintDocument
        Dim intTray As Integer
        Dim intRedTray As Integer = 0
        cbRedTray.Items.Clear()
        ' Add list of paper sources found on the printer to the combo box.
        ' The DisplayMember property is used to identify the property that will provide the display string.
        strPrinter = cbBlackWhite.SelectedItem
        printDoc.PrinterSettings.PrinterName = strPrinter
        For intTray = 0 To printDoc.PrinterSettings.PaperSources.Count - 1
            pkSource = printDoc.PrinterSettings.PaperSources.Item(intTray)
            cbRedTray.Items.Add(New DataItem(pkSource.RawKind, pkSource.SourceName))
            If UCase(Trim(pkSource.SourceName)) = "TRAY 2" Then
                intRedTray = intTray
            End If
        Next
        cbRedTray.SelectedIndex = intRedTray

And then where I handle the word document:

dim DI as DataItem = cbRedTray.SelectedItem
dim lngTray as Long 
dim oWord as New Word.application
dim oDoc as Word.Document
....
lngTray = DI.ID
oDocPageSetup.FirstPageTray = lngTray
oDoc.PageSetup.OtherPagesTray = lngTray
G_Waddell 131 Posting Whiz in Training

HI Guys,

I have written an app the prints out batches of documents for postings. Each batch is to be seperated by a red coversheet.

I know that in our printing department, no matter what printer they use to print the batches on to they will always have the red paper in Tray 2.

My issue is that when I create my coversheet as a word doc and go to print it, I want to point it at this tray. I found the tray using System.drawing.printer settings and I tried to point the Word doc at this tray but I got the following build error:

Error 1 Value of type 'System.Drawing.Printing.PaperSource' cannot be converted to 'Word.WdPaperTray'.

My code to find the tray is this ( the printer has already been selected by a combobox and I'm putting the trays into another combo so they can override):

dim strPrinter as string
 strPrinter = cbBlackWhite.SelectedItem
cbRedTray.DisplayMember = "SourceName"
        printDoc.PrinterSettings.PrinterName = strPrinter
        For intTray = 0 To printDoc.PrinterSettings.PaperSources.Count - 1
            pkSource = printDoc.PrinterSettings.PaperSources.Item(intTray)
            cbRedTray.Items.Add(pkSource)
            If UCase(Trim(pkSource.SourceName)) = "TRAY 2" Then
                intRedTray = intTray
            End If
        Next
        cbRedTray.SelectedIndex = intRedTray

Then when I'm printing the coversheet I was trying to use:

oDoc.PageSetup.FirstPageTray = cbRedTray.SelectedItem
oDoc.PageSetup.OtherPagesTray = cbRedTray.SelectedItem

So my question is should is there a way to convert one type to the other or which method should I be using to specify the tray?

In other words, is there a way in Word to parse through trays and …

G_Waddell 131 Posting Whiz in Training

Sorry, I'm just trying to understand exactly what is happening you say:

The problem is as follows:
Each salesperson is assigned a 4 character ID, with the first character either an F (full-time) or a P (part-time). And the last character is either a 1 (sells new cars) or a 2 (sells used cars).

I need to create an application that allows the sales manager to enter a ID and the number of cars the salesperson sold during the month. The app should all the sales manager to enter this info for as many salespeople as he likes. The app needs to calculate and display the total number of cars sold by each of the following: full-time employees, part-time employees, employees that sell new cars and employees that sell used cars.

Do you mean that the manager enters the data for a single salesperson in then the next and gets a running total? Or do you mean that they enter multiple user ID at once and want to display the totals?

I'll assume the first scenario - the running total. the issue is that with each click you are "resetting" the totals:

If id.StartsWith("F") And id.EndsWith("1") Then            
noFulltimeLabel.Text = carsSoldTextBox.Text           'i.e. the noFulltimeLabel text is now the same as the carsSoldTextBox text

What you want to do is something like this:

If id.StartsWith("F") And id.EndsWith("1") Then            
noFulltimeLabel.Text = Cint(noFulltimeLabel.Text)  + Cint(carsSoldTextBox.Text )
G_Waddell 131 Posting Whiz in Training

hi
im trying to retrieve data from a foxpro database in a date range selected by the user from 2 datetimepicker boxes

dim date1, date2 as date

date1=datetimepicker1.value.date
date2=datetimepicker2.value.date
i used this command
oSql="select * from customer where between(customer.date,{^date1},{^date2})"
an empty table comes up.....can any one help pleas

Hi
There are a few things I'd suggest to try and troubleshoot this:

Looking at your code, you have put your select statement into a string but where you mean to pass in the date values you have just put the text date1 and date2 i.e. instead of:

oSql="select * from customer where between(customer.date,{^date1},{^date2})"

You should have:

oSql="select * from customer where between(customer.date,{^" & date1 & "},{^" & date2 & "})"

If this is does not work then try:

oSql="select * from customer "

to ensure you have connected to the database and have records in the table.
The actual syntax of your SQL looks off to me but I have never used FoxPro so I can't really comment. Although, I would use (for SQL Server):

oSql="select * from customer WHERE (customer.date > '" &date1 &"') AND ( customer.date <'" &date2 &"')"
G_Waddell 131 Posting Whiz in Training

You basically want to find a piece of text within another piece of text?

function findit(byRef TheText) as integer
dim i as integer
i=instr(RichTextBox1.text, TheText)
return i
end function

or if you wish to find all occurances something like this will do (I'm a bit rusty with arrays in VB.net):

function findit2(byRef TheText) as integer
dim Results() as integer
dim i as integer =1
dim y as integer =0 
redim Results(0)
While i < len(RichTextBox1.text)
  i=instr(i,RichTextBox1.text, TheText)
  Redim Preserve Results(Ubound(Results)+1)
  Results(y) = i
  y=y+1
  i =i+1
End while
return Results
G_Waddell 131 Posting Whiz in Training

Hi
I think you are looking for a data item....

e.g.

sub populatecomboboxManually ()
dim MyCombo as New Combobox

'do whatever you need to get your data.....
for i = 1 to 10
'New DataItem(ID (is not displayed) , Value (is displayed))
MyCombo.items.add(New DataItem(i,MyValue))
Next
end sub

sub readvaluefromcombo()
dim myDi as DataItem
dim myID as integer 'can of course be anything you want
dim myValue as String 'as above
myDI = MyCombo.SelectedItem
MyID = DI.ID
MyValue = DI.Value
end sub

As I said you can manually populate your dataitem. I usually use an integer for the ID..

Or you can read in values from a database and use something like primary key for ID and whatever field you want for value. As long as the ID is unique it will work. Just because you have to put ID and values into the dataitem doesn't mean you have to use both in your code.

G_Waddell 131 Posting Whiz in Training

Here is a good site for finding out what connections you need to use to connect a datasource (e.g. SQL Server, Excel, Oracle etc) to your code.

www.connectionstrings.com

G_Waddell 131 Posting Whiz in Training

Lots of different ways you can do the import but automatting Excel is probably the last one I would pick. First if you are importing directly from an Excel file, there is no reason to automate Excel at all. Using OLEDB you can read the values straight from the file into a dataset/datatable. This has an added advantage of not needing the user to also have the same version of Excel installed on the computer. Second there is no need to convert a CSV file before doing an import, there are many methods available for reading/importing delimited files. Not that it matters but you mention your using ODBC to read the Excel file, I dont see ODBC being used at all in your example.

I would suggest starting out by taking a look at the "TextFieldParser" in the help file. It has full examples for reading delimited files without the need to convert them to a different format.

Yes the problem I was having was doing the convert from csv to Excel I had alreaduy got a routine working for importing the data from Excel file via Obdc - the csv /excel files are not coming in a standard format and I wanted the user to able to map the fields from Excel into the address table in SQL and also dedupe by running a select Distinct query.

Anyway, my code is working now which leads me to the following conclusions:
1. My previous attempts to work with …

G_Waddell 131 Posting Whiz in Training

Hi Guys,

I'm obviously missing something here.

Basically I'm writing a program that will read in a csv file or excel file, and allows the user to pick which fields thay wish to use for what line of an address, and then import all the addresses to a SQL table for later processing.

I got the excel import working by opening it through ODBC as a database and reading it in and I thought that I'd save time by just converting the csv to excel and reusing the Excel routine on my new Excel file but I'm having difficulty with the csv conversion.

Here is what I'm using:

private sub ConvertCSV(OldName, NewName)
Try
                XL = New Excel.Application
                XL.Visible = False
                XL.Workbooks.OpenText(OldName)
                XL.DisplayAlerts = False
                XL.ActiveWorkbook.SaveAs(NewName, Excel.XlFileFormat.xlExcel9795, , , , False)
                XL.ActiveWorkbook.Close(False)
                XL.Quit()
                XL = Nothing

            Catch ex As Exception
                sError = ex.ToString ' Returns error details 
                MsgBox(sError, MsgBoxStyle.OkOnly)
                Debug.WriteLine(ex.ToString)
            End Try

end sub

The trouble is that when it then goes into my Excel Address routine, the new excel file appears to be empty.

I see an excel file outputted to where I want it on the computer but it will not open for me (no errors given excel just hangs)

Any ideas or will I have to parse the CSV file line by line into Excel?

G_Waddell 131 Posting Whiz in Training

You have read my thoughts :)) This is exactly what I was looking for.

Thank you !!!

Glad I could help, I hope it is all resolved for you now.

G_Waddell 131 Posting Whiz in Training

Hi All,

I managed to figure it out, I should have closed with:

oWord.Application.Quit(False)
G_Waddell 131 Posting Whiz in Training

Hi,

I'm writing a function that takes a word doc and returns the number of pages in it. I have the function working and returning pages except that it opens a Word dialog asking if I want to save changes - does anyone know how to stop this? I have the document running "silently" in the background so I don't want to spoil the feel by prompting for saves.
Here is my code:

Private Function CountWordPages(ByRef Doc As String) As Integer
        Dim oWord As Object
        Dim WD_Doc As Word.Document
        Dim intCount As Integer = 0
        On Error GoTo ErrorHandler
        oWord = CreateObject("Word.Application") 'late bind for differing versions of word
        WD_Doc = oWord.Documents.Open(Doc, True, True, False, , , , , , , , False) 'open silently in background
        intCount = WD_Doc.ComputeStatistics(Word.WdStatistic.wdStatisticPages) 'get count
        WD_Doc = Nothing 'done with the doc
        oWord.Application.Quit() ' close the app
        oWord = Nothing 'tidy up
        CountWordPages = intCount 'return count
        Exit Function
ErrorHandler:
        DisplayError(Err.Number, Err.Description)
    End Function

Thanks in advance

G_Waddell 131 Posting Whiz in Training

Hi
As I understand it you are passing a query into your class and wish to read the data from it. It looks to me like the issue is caused here:

Dim i As Integer = -1        
 While MySQLreader.Read            
            i += 1            
             ReadData += MySQLreader.GetValue(i).ToString         
End While

1.The line While MySQLreader.Read will cause the reader to read from each row in turn
2. You are not moving through each field returned with the record as your i value is not increasing within the record.
3. I also would not assume a value limit for i so that you can pass queries with various number of fields in the result.

Here is how I would do it:

Dim ReadData As String        
Dim i As Integer    
      
While MySQLreader.Read               'Read in the row
    i=0 'reset i to start from first field
    'loop through each returned field and add to the string
    for i = 0 to MSQLreader.FieldCount - 1  
                ReadData += MySQLreader.Item(i).ToString
    next
End While
Return ReadData
ShemoPT commented: Helpfull Post!!! +0
G_Waddell 131 Posting Whiz in Training

You probably can guess this from the previous threads but I use:

dim MyTable as Datatable
'fill datatable....
If (MyTable Is Nothing) Or (MyTable.Rows.Count =0 ) Then
'it's empty
Else
'it exists and there are rows 
End if