Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42475

urgent help needed: mysql/sql database, checking for duplicates/adding line

$
0
0
Let's call my program FortuneSender.exe, it's made to send Fortune cookie messages to my forum members. Currently it sends 1 fortune to each member per month via forum PM function. They have to contact me VIA pm requesting it. Sometimes members request multiple fortunes per-month & they are only allowed to receive one. So to be sure my program does not send more than 1 to the same forum user, I incorporated the following subs into my program, it creates a blacklist of usernames I've already sent a fortune to this month......I am looking for a better way, more 'real time' way of doing this, so if i need to run multiple programs, from different locations at the same time, I don't end up sending more than 1 to 1 person.

Code:

Private FortuneBlacklist As New List(Of String)

    Private Sub SaveFortuneBlacklist(ByVal fileLoc As String)
        IO.File.WriteAllLines(fileLoc, Blacklist.ToArray) 'writes all the entries of FortuneBlacklist to array... line by line to a file
    End Sub

    Private Sub RetrieveFortuneBlacklist(ByVal filepath As String)
        FortuneBlacklist.AddRange(IO.File.ReadAllLines(filepath)) 'loads the blacklist into memory
    End Sub

    On Form_Load I call on...
    RetrieveFortuneBlacklist("FortuneBlacklist.txt")

    Then in Form_Closed I call on....
    SaveFortuneBlacklist("FortuneBlacklist.txt")

    And during the main function of "SEND_FORTUNE"......I start it out with this........before going on with the forum PM function
            Dim username As String =  some html code on my forum
            If Not FortuneBlacklist.Contains(username) Then
            FortuneBlacklist.Add(username)

This worked perfectly when running 1 program....however, I want to be able to run it on more of my forums, run more copies of it etc. And I need this FortuneBlacklist to be in real time, instead of relying on its own starting array. I want it to be in real time. So what I need to do is to set up this same function, VIA sql/mysql/or a database of sorts, on my webserver. So that both of my programs, no matter where/when i run them, will all be checking/adding to the same DB/or list. Can someone show me a simple way to perform the functions above using MYSQL/SQL or some sort of db/file i can use on my webserver. So that instead of relying on it's own "internal array" after loading/and saving when finished. It constantly refreshes the FortuneBlacklist array from the database/and also saves it's newest added username to the database in real time, instead of when it's finished. That way none of the programs running have any chance of sending a PM to the same user twice. Now I know nothing about mysql/sql, I do know how to set up a database though on a webserver. However it would be just as easy for me to do it with a text file on a webpage, via php etc. So i just need a basic idea of how I can accomplish this.

EDIT: Just had an idea, but don't know how to do this........
Or could I simply host FortuneBlacklist.txt at C:\FortuneBlacklist.txt, & before each send.....load the text to blacklist.array, then upon sending, add just the 1 (latest line) to the blacklist. That way either program running isn't accidentally re-saving (it's own version) of the entire blacklist at any given time, which may not contain the user name program2.exe just added 1 second previous?
How do you write just the most recent line in an array to the next available blank line in a text file, that another program may have just added its own line to? I.E. it won't know which line to add to by keeping count of how many lines its written, instead it would need to know to write to whatever the last line in the file is.

Viewing all articles
Browse latest Browse all 42475

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>