UKnod 16 Newbie Poster

Ah, yes of course, hadn;t thought of cookies, I will look up how to use those, thanks for the advice.
Geoff.

UKnod 16 Newbie Poster

I am using visual basic dot net, with the asp.net add on. I have created a programme which works great, basically it has a logon, which uses mysql for the data, then loads a 2nd page using the username data. I am using the global variable to store the username between pages. Its all good, untill another person logs in at the same time as the first user, now when they log on, user 1 now has the globale variable of the 2nd user.
What I need is a globale variable that is unique to each user. Any idea how this is done, I am very new to asp.net.

UKnod 16 Newbie Poster

Thanks for everyones help on this.

UKnod 16 Newbie Poster

ah of course it is that explains it perfectly.

UKnod 16 Newbie Poster

Another interesting thing to watch out for is the default device needs to use devicenumber 0 rather than is actual device number, otherwise it does not play. Just a windows odity I guess.

UKnod 16 Newbie Poster

If I use the code mplayer1.Dispose()
this will end the current playing audio. Is that correct. So if I reuse the code mplayer1 = New WaveOut() does that mean I have effectily dissposed of the first audio?
So could the code go

mplayer1.Dispose()
mplayer1 = New WaveOut()

to end the first sound and start the new one. Would that stop any leakage.

UKnod 16 Newbie Poster

yep, how do I mark it as solved?

UKnod 16 Newbie Poster

OK, After all that I finally (with the help of https://www.daniweb.com/members/815196/xrjf) worked it out so here is the simplified code to play two different sounds out of two different cards at the same time.

Imports NAudio
Imports NAudio.Wave
Public Class Form1

    Private mplayer1 As WaveOut
    Private mplayer2 As WaveOut
    Private filereader As AudioFileReader

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        filereader = New AudioFileReader("C:\first_track.mp3")
        mplayer1 = New WaveOut()
        mplayer1.DeviceNumber = 0
        mplayer1.Init(filereader)
        mplayer1.Play()

        filereader = New AudioFileReader("C:\second_track.mp3")
        mplayer2 = New WaveOut()
        mplayer2.DeviceNumber = 1
        mplayer2.Init(filereader)
        mplayer2.Play()

    End Sub
End Class
UKnod 16 Newbie Poster

perfect, thats what I was looking for.
Tried it on the sample code and it works for first play, but you cant change it, but I'll work on that now I have the code for devicenumber, perfect thanks.

UKnod 16 Newbie Poster

what do you mean by stick to the sample, as the sample does not work as it does not change the sound card?

UKnod 16 Newbie Poster

Yes thank you for this code. However, changing the sound card does not change the sound card. It still plays through the same one. This is the problem I am having.
I can;t work out where the actual changing of the card code is, I can see it is the variable devNum but I cant see where devnum actually changes the output. Which in fact it doesn't.

UKnod 16 Newbie Poster

Thanks for the code, does this mean devnum is the sound card that I want to use after selecting the combo box?

So how do I make it play the sound from that sound card.

By the way this is all from code, so I wont be using combo boxes etc.

Currently I have MPLAYER.Play()
Which I need it to come out of a different sound card.
I also want to be able to play two different sounds out of two different card at the same time

UKnod 16 Newbie Poster

yes understand, It is difficult to describe vb.net (basic) rather than vb.net (c) I need the basic vertion.

UKnod 16 Newbie Poster

Unfortunatly all in c# with no real corelation vb.

rproffitt commented: The library is for .NET apps. VB.NET is .NET. However I understand that people want code for their choice of .NET language. +16
UKnod 16 Newbie Poster

OK, got it all installed and using the following code:

filereader = New AudioFileReader("C:\Users\Geoff\Desktop\audio\Alice Cooper - Schools Out.mp3")
        MPLAYER.Init(filereader)
        MPLAYER.Play()

It plays perfect. Any idea how to change the sound card, I think its got something to do with waveout. but not sure on the actual command.

UKnod 16 Newbie Poster

Thanks, certainly looks like its what I'm after, only problem is it looks like it c# rather than vb and its a complicated install, but I'll give it a go.

UKnod 16 Newbie Poster

I am using visual studio / basic 2019. using the windows media to play sounds (WMPLib.WindowsMediaPlayer).
It works great, I can play multiple sounds etc. However what I realy want to do is play some sounds on sound card A. And other sounds in sound card B.
I am thinking that changing the default sound card, then playing the sound, then changing the defualt sound card and playing another sound might be the way to go, but I think when the sound card changes all the currently playing sounds stop.
Has anyone got any ideas how to acheieve this.

UKnod 16 Newbie Poster

Thanks for the reply. Looks good, but I could not get it to work. Not sure exactly how to use class's in this way, if it had been an example of say populating a text box, then I might have got it. I will endevour to try to learn.

UKnod 16 Newbie Poster

In the good old days of VB6 I used to use this technique to communnicate between programmes, without using external files. In fact I could even set off the textbox interupt in the running programme so as it could do something once triggered.
This being said, I can't get it working on dot net. Does any one have any idea on how to setup the same type of programme using dot net.

UKnod 16 Newbie Poster

whats an enum?

UKnod 16 Newbie Poster

I have written some code to make an outlook addin, which is working great. Except that the to field from outlook is displaying the contact na,e instead of the actual real address. IE it is displaying geoff instead of someone@gmail.com unfortunatly I want the who address not just the shortened version. Does anyone know where to get this.
My doe simply uses .To

UKnod 16 Newbie Poster

Excelent, working now, thanks for your help.

UKnod 16 Newbie Poster

Ok, now this looks different than before.

Heres what I have got in my simplistic view.

    Dim con As New ADODB.Connection
    Dim rec As New ADODB.Recordset

    con.ConnectionString = ("Driver={Microsoft Access Driver (*.mdb)};Dbq=addressbook.mdb;Uid=admin;Pwd=12345678;")
    Dim x1(100), x2(100), x3(100)
    Dim contactID = 1

        'this is how to change a record
        con.Open()
        Dim sql
        sql = "UPDATE tblContacts SET Contact1 = 'Fred' WHERE ContactID = " & contactID
        con.Execute(sql)
        con.Close()

        'this is how to step through records and populate x1,x2,and x3
        con.Open()

        sql = "SELECT Contact1,Contact2,Contact3 FROM tblContacts WHERE Contact1 like 'S%'"
        rec.Open(sql, con, CursorTypeEnum.adOpenStatic)
        Dim n
        Do Until rec.EOF
            n = n + 1
            x1(n) = rec("Contact1").Value
            x2(n) = rec("Contact2").Value
            x3(n) = rec("Contact3").Value
            rec.MoveNext()
        Loop
        rec.Close()
        con.Close()

        'This is how to delete a record

        con.Open()
        Dim sql
        sql = "DELETE FROM tblContacts WHERE ContactID = '1234'"
        con.Execute(sql)
        con.Close()

So if this will work there is only the how to insert a record that I am missing.
This is just using ADO, What do you think.

UKnod 16 Newbie Poster

Hi
Thanks for the info, I now understand how it works, but I am having trouble converting to mdb.

Here is what I have.
for setup

Imports System.Data.OleDb
Imports System.Data.SqlClient

But I think that the second one should not be SQL.
And I think I have to add the ADO reference

for connection

     Dim con As New ADODB.Connection
     con.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\addressbook.mdb;Uid=admin;Pwd=12345678;")

To open a sql string

rec.Open("SELECT au_lname FROM authors WHERE au_lname like 'S%'", con, CursorTypeEnum.adOpenStatic)

but what is rec ?

On VB6 is would be a recordset, but there isn;t one of those on .net

And even if it worked what do I do with the SQL string now I have it open?

So I could try:

 Dim cmd As New SqlCommand("", con)
 cmd.CommandText = "SELECT * FROM tblContacts WHERE ContactID =" 1234 "" ORDER BY ID"

and then to populate a variable I need a reader:

Say there was just one record in the above then

 con.Open()
 Dim rdr As SqlDataReader = cmd.ExecuteReader
 rdr.Read()
 x={rdr("au_lname")}


 rdr.Close()
 con.Close()

but again what is SWLCommand in MDB?

And to write back:

    con.open()
    con.Execute("UPDATE authors SET au_fname = 'Dave' WHERE ID = '1234'")
    con.close()

This would change one field au_fname to Dave in record ID 1234

Sorry to be thick, but as you see I am a little confused.

UKnod 16 Newbie Poster

Hi
Thanks for the info. I understand now how to read data with the required SQL string, this is great. However how do I now write data, and make new records using the same technique, update records etc.

UKnod 16 Newbie Poster

OK Thanks for this, but I am using Access MDB.

Your way looks way beter but I am a little confused with the syntax.
It seems that in fact I have been using OLEDB not ADO.
Here is a typical lookup that I would use:

        Public con As New OleDb.OleDbConnection
                dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source =" & app_path & "\AddressBook.mdb;"
        password = "Jet OLEDB:Database Password=12345678;"

        con.ConnectionString = dbProvider & dbSource & password

 con.Open()

        sql0 = "SELECT * FROM tblContacts order by contactID"
        da0 = New OleDb.OleDbDataAdapter(sql0, con)
        da0.Fill(ds0, "AddressBook")

 con.Close()

The trouble is, this is stored locally, the fill command take forever to run as it loads the complete table, and any changes dont go to the network until the programme closes or you invoke a comandbuilder, all of which takes ages, when most of the time I just want to change one record.

So your example looks like it does exactly what I am wanting but I am not sure how to convert it to something similar to above.

UKnod 16 Newbie Poster

I can open word, replace words, create word documents, but I can find any way of opening a word document and reporting back that a certain word or prase has been found or not. I see there is a function word.find.found but it never seems to report back anything but false, does anyone know how to use this function properly.

UKnod 16 Newbie Poster

I have writen a few DB programms in ADO.net now, and I hate it. It is riddle with confusion and problems, and because of the ridiculous idea of using all the data locally, it makes networking neigh on impossible and incredibly slow, so please please someone show me how to use DAO on dot net. All I want to know is:
how to make a connection
how to add a record
how to delete a record
and how to edit a record.
Just like in the good ol VB6 days.

UKnod 16 Newbie Poster

there isn't a selection option

oDoc is a word.document

UKnod 16 Newbie Poster

I am able to find and replace in word, however all I want to know is if the word was found, I have tried the following code:
This works

     oDoc.Content.Find.Execute(FindText:=x, ReplaceWith:=y, Replace:=Word.WdReplace.wdReplaceAll)

This never give the true statement

                     oDoc.Content.Find.Text = x
                        If oDoc.Content.Find.Found = True Then

But why not?

UKnod 16 Newbie Poster

Actually I got it

I put in POPerrors = ""

in the function and that got rid of it.

UKnod 16 Newbie Poster

could you give me an example
thanks

UKnod 16 Newbie Poster

I am in this position again with warning that I cant get rid of, Here is the code:

Public Function POPErrors(ByVal strMsg As String)

        MsgBox("POP3 ERROR - " & vbNewLine & strMsg, MsgBoxStyle.Critical)

End Function

Here is the warning:
Function 'POPErrors' doesn't return a value on all code paths. A null reference exception could
occur at run time when the result is used.

What does that mean?
And how do I get rid of it.

UKnod 16 Newbie Poster

OK Thanks, thats what I needed to know.

UKnod 16 Newbie Poster

Yes I know that, but my question is, how do I stop that. I want it in the order of the IN(a,c,b) not a.b.c

UKnod 16 Newbie Poster

Im an idiot, I just realised my mistake. But it has not solved my problem, what I now need is the order to be in the order of the IN statement.
For example

SELECT * FROM tblContacts WHERE ContactID IN (1857,2141,2145,2150,1017,1353,3683,3906,3056,3246,3509);

But I want the order of 1857,2141,2145,2150,1017,1353,3683,3906,3056,3246,3509 not numerical. The SQL sorts it automatically, but I dont want it sorted.

UKnod 16 Newbie Poster

Yes already tried that, error I get is No value given for one or more required parameters.

I am using Access mdb.

UKnod 16 Newbie Poster

I am having a little difficulty witht he syntax of a lookup using access DB

here is the code:

"SELECT * FROM tblContacts WHERE ContactID IN (353,1520,2031); Order by ContactID"

It works find without the order and I have tried without the ; or with the ; at the end, but no luck.

Anyone genious enough to know the correct syntax.

UKnod 16 Newbie Poster

As an update, I have now tried it with fdifferent amounts of BCC, and it is ok upto 5 then it errors.

UKnod 16 Newbie Poster

I am using system.net.mail for my email application and it works fine, untill I try to send multiple BCC address's. I can't work out why it is failing I get a long message from my try trap which basically says the server response was repeat limit reached. However I don't think it is the server, becasue it comes back too quickly, also if I make the list shorter, ie just 10 address's it still comes back withthe same message, After thining about it I will try just 2 to see what happens.
I think it is some kind of syntax with the emails. like it is finding duplicates or something. Anyone else come accross this.

UKnod 16 Newbie Poster

Thanks thats great.

UKnod 16 Newbie Poster

Althought this code works most of the time, when I get an error it doesn;t help much, is there a way offinding out details of errors.
I have tried.

Dim smtperror As New SmtpException
            x = smtperror.Message

and I get x equalling 100 ??

UKnod 16 Newbie Poster

Windows live mail.

UKnod 16 Newbie Poster

Yes this worked very well for using SMTP direct, I think I will change to using that method, I wonder if there is a method which can add to the default mail client sent items, even though it won't actually be sending the email.

UKnod 16 Newbie Poster

I have an email programme that works sometimes, but mostly comes up with a general Mapi failure. I am at a loss as to the reason, but it may be a good idea to not use the mapi controls anymore if it is going to cause errors. I have looked at SMTP options using system.net.mail but I cant figure out how to send attachments, also it is nice to have a copy of the email in the default mail client which MAPI does. Anyone got any ideas as the best way to send emails using vb.net.

UKnod 16 Newbie Poster

Hi
Yes that worked a treat, but look at that ADO code, the same as VB6, I never new you could do that, its great, so why do it the other way, ie ole I guess whatever that is. Is there any advantage of using one over the other? Because if not then I shal go back to using the old method. ALso can you have ADO and OLE in the same programme, like for example using OLE for the customer contact records but ADO for the history etc.

UKnod 16 Newbie Poster

OK I changed your code to this:

        Dim cn As New OleDb.OleDbConnection(dbProvider & dbSource & password)
        'create command to use
        Dim cmd As New OleDb.OleDbCommand("tblHistory", cn)
        cmd.CommandType = CommandType.TableDirect
        ' create a dataadapter and commandbuilder for it
        Dim da As New OleDb.OleDbDataAdapter(cmd)
        Dim cb As New OleDb.OleDbCommandBuilder(da)

Which seems to get rid of all the errors and makes a little more sense to me and runs. However it doesn't save any data in the table. Have I done the wrong thing.

UKnod 16 Newbie Poster

Oh and the field definitions are 7 fields the first being an auto number.
ID
Datee
Type
Userr
Regarding
Attachment
ContactID

UKnod 16 Newbie Poster

Hi
Thanks for this, however. I am a VB6 man at heart and it is so easy to do this on VB6. I understand that my code may be nasty, but it is the only way I can make it work by saving the data to disc rather than in memnory so as others can see the changes, this is why it is nasty!
That being said I dont need the history in memory so your solution will be fine if I new how you did it, it is a little over my head. Forgive me for being a little slow but how do I declare the oledbconnection and make the connection to the DB.
Thisis how I am doing it at the moment:

dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source =" & app_path & "\AddressBookLayout.mdb;"
        password = "Jet OLEDB:Database Password=12345678;"
        con2.ConnectionString = dbProvider & dbSource & password

Cheers.

UKnod 16 Newbie Poster

I am running a database with about 200,000 records, so not too big. It runs fine except when I try to update one of the tables. Here is the code:

      Private Sub Add_History()

        Dim cb5 As New OleDb.OleDbCommandBuilder(da5)
        Dim dsNewRow5 As DataRow

        Dim sql5 As String
        sql5 = "SELECT * FROM tblHistory order by ID"

        dsNewRow5 = ds5.Tables("History").NewRow()

        ds5.Tables("History").Rows.Add(dsNewRow5)

        da5.Update(ds5, "History")

        da5.Dispose()
        ds5.Clear()
        da5 = New OleDb.OleDbDataAdapter(sql5, con)
        da5.Fill(ds5, "History")

        da5.Update(ds5, "History")

        New_hist()
errr:
    End Sub

      Private Sub New_hist()

        Dim cb5 As New OleDb.OleDbCommandBuilder(da5)
        Dim x
        On Error GoTo errr

        ds5.Tables("History").Rows(Hist_Rows - 1).Item(6) = contactID
        ds5.Tables("History").Rows(Hist_Rows - 1).Item(1) = DateTime.Now
        ds5.Tables("History").Rows(Hist_Rows - 1).Item(3) = username

da5.Update(ds5, "History")

    End Sub

Its the da5.Fill(ds5, "History") that takes about 10 seconds to fill. If there are no new updates, ie I dont use

            dsNewRow5 = ds5.Tables("History").NewRow()

            ds5.Tables("History").Rows.Add(dsNewRow5)

            da5.Update(ds5, "History")

then it fills instantly. It seems that when you want to add a record the fill takes forever.

Anyone got any ideas how I can speed this process up.