VB/ASP Sending SMS to multiple number in database using For Each - sql

Hey guys can someone give me an idea for this:
for example i have a database filled with the numbers of the contacts i want to send my sms with. how can i use for each to read all the numbers and send the sms to them. like this one ? i dont know the correct syntax yet
Example:
database: tblnumbers
for each(number in the tblnumbers)
{
execute my sms code to send to the numbers.
}
thats my logic only.

Well, the below could give you a very broad idea of what is required here... There simply isn't enough information to give you an accurate answer. This question should probably be closed for being too broad...
Please note, the below code uses my own helper classes. It's for demonstration only.
I suggest you research how to interact with databases using .NET and how to populate and manage collections such as lists, dictionaries and arrays.
private sub SendSms()
Const query as string = "SELECT * FROM [TBLNUMBERS]"
using dr as new DataReader(_globals.Dif)
dr.ExecuteReader(query)
do While dr.read()
dim telNo as integer = dr.Item("TELEPHONE_NO")
'Do something with the telephone number...
Loop
End Using
End sub

Related

Match Words and Add Quantities vb.net

I am trying to program a way to read a text file and match all the values and their quantites. For example if the text file is like this:
Bread-10 Flour-2 Orange-2 Bread-3
I want to create a list with the total quantity of all the common words. I began my code, but I am having trouble understanding to to sum the values. I'm not asking for anyone to write the code for me but I am having trouble finding resources. I have the following code:
Dim query = From data In IO.File.ReadAllLines("C:\User\Desktop\doc.txt")
Let name As String = data.Split("-")(0)
Let quantity As Integer = CInt(data.Split("-")(1))
Let sum As Integer = 0
For i As Integer = 0 To query.Count - 1
For j As Integer = i To
Next
Thanks
Ok, lets break this down. And I not seen the LET command used for a long time (back in the GWBASIC days!).
But, that's ok.
So, first up, we going to assume your text file is like this:
Bread-10
Flour-2
Orange-2
Bread-3
As opposed to this:
Bread-10 Flour-2 Orange-2 Bread-3
Now, we could read one line, and then process the information. Or we can read all lines of text, and THEN process the data. If the file is not huge (say a few 100 lines), then performance is not much of a issue, so lets just read in the whole file in one shot (and your code also had this idea).
Your start code is good. So, lets keep it (well ok, very close).
A few things:
We don't need the LET for assignment. While older BASIC languages had this, and vb.net still supports this? We don't need it. (but you will see examples of that still floating around in vb.net - especially for what we call "class" module code, or "custom classes". But again lets just leave that for another day.
Now the next part? We could start building up a array, look for the existing value, and then add it. However, this would require a few extra arrays, and a few extra loops.
However, in .net land, we have a cool thing called a dictionary.
And that's just a fancy term of for a collection VERY much like an array, but it has some extra "fancy" features. The fancy feature is that it allows one to put into the handly list things by a "key" name, and then pull that "value" out by the key.
This saves us a good number of extra looping type of code.
And it also means we don't need a array for the results.
This key system is ALSO very fast (behind the scene it uses some cool concepts - hash coding).
So, our code to do this would look like this:
Note I could have saved a few lines here or there - but that would make this code hard to read.
Given that you look to have Fortran, or older BASIC language experience, then lets try to keep the code style somewhat similar. it is stunning that vb.net seems to consume even 40 year old GWBASIC type of syntax here.
Do note that arrays() in vb.net do have some fancy "find" options, but the dictionary structure is even nicer. It also means we can often traverse the results with out say needing a for i = 1 to end of array, and having to pull out values that way.
We can use for each.
So this would work:
Dim MyData() As String ' an array() of strings - one line per array
MyData = File.ReadAllLines("c:\test5\doc.txt") ' read each line to array()
Dim colSums As New Dictionary(Of String, Integer) ' to hold our values and sum them
Dim sKey As String
Dim sValue As Integer
For Each strLine As String In MyData
sKey = Split(strLine, "-")(0)
sValue = Split(strLine, "-")(1)
If colSums.ContainsKey(sKey) Then
colSums(sKey) = colSums(sKey) + sValue
Else
colSums.Add(sKey, sValue)
End If
Next
' display results
Dim KeyPair As KeyValuePair(Of String, Integer)
For Each KeyPair In colSums
Debug.Print(KeyPair.Key & " = " & KeyPair.Value)
Next
The above results in this output in the debug window:
Bread = 13
Flour = 2
Orange = 2
I was tempted here to write this code using just pure array() in vb.net, as that would give you a good idea of the "older" types of coding and syntax we could use here, and a approach that harks all the way back to those older PC basic systems.
While the dictionary feature is more advanced, it is worth the learning curve here, and it makes this problem a lot easier. I mean, if this was for a longer list? Then I would start to consider introduction of some kind of data base system.
However, without some data system, then the dictionary feature is a welcome approach due to that "key" value lookup ability, and not having to loop. It also a very high speed system, so the result is not much looping code, and better yet we write less code.

Discord.NET sending messages to one specific channel in one specific server

So I'm trying to send a message to a specific channel, but I've been looking and found I can't see any way I can do that. I might be doing something wrong or I'm looking in the wrong area, I've looked on Google and couldn't find an answer. This is my code when trying to find it.
discord.GetGuild("serverid").GetChannel("Channelid")
As far as I can see, this is not the way to do it, but I don't know where else to check :\
Actually, I kinda feel stupid after realizing this, In my code previously, I was making the program try and find a channel, when what I actually needed to do was find a text channel, like so:
discord.GetGuild("serverid").GetTextChannel("Channelid").SendMessageAsync(
"Message")
So sorry for asking for help when the answer was really simple.
:/
when getting the channel you dont need to get the guild, all channels is inside your client
so
discord.GetTextChannel("id").SendMessageAsync("message")
would be enough
I know this is an old post but for what it is worth this was my solution. The code is in vb and it works perfectly.
Check out .GetAwaiter().GetResult() at the end of the SendMessageAsync() function. That allows me not to have to put 'await' before that line :).
Oh and guild and channel ids are not strings but of Long type
I get the IDs from server by searching for the names of each :). So no need to know the IDs before hand :).
Oh and this function is not of Async type so in your code you need to make adjustments if you are using it as an Async task.
Also the _guild.id and _channel variables are of type ULong. VB allows u to declare a variable without stating what type it is. VB will automatically detect what type it is based on what is on the right side of the declaration.
Sub sendMessageToChannel(ByVal server As String, ByVal channel As String, ByVal msg As String)
Try
Dim _guild = _client.Guilds().First(Function(z) z.Name = server)
Dim _channel = _guild.TextChannels().First(Function(z) z.Name = channel).Id
_client.GetGuild(_guild.Id).GetTextChannel(_channel).SendMessageAsync(msg).GetAwaiter().GetResult()
Catch ex As Exception
Debug.Print("Error:" & Constants.vbCrLf + ex.ToString())
End Try End Sub

Make pc specific hash in vb.net

I want to make a program, which generate the same string each time, and it must be different on any each pc. So like HWID. After I have the string I send it into a php file on a remote host, the php handle it, and store it in the database.
On the first run it will make a new row in the table, but after 2nd run, it will select the row where the POST-ed hash = the hash in the table, and it has banned - not banned function. So if I give back 0 the pc is not banned, so program start to run, if I give back 1 the program close.
This is all made, my problem is, I generate hwid from processorid, and send it to the php. the processorid can be the same on different computers sometimes. So if I give fake ban, the users will be angry for me...
The question is:
How to generate a hash, which will be always the same on the pc which run the application, but different on each pc?
I know I can make it if I store a special id on the pc for example in the registry, but if somebody reinstall the pc, he can use again the service. If I generate hwid, it will takes him more time to find out how to access again to the service.
I dont think this really has anything to do with PHP, but entirely about the client side steps.
To do what it sounds like you want, you want to use a hardware signature made up of several things so that if one or two are unavailable, the result is still valid. This will use a form of the WMI polling procedure from the answer on your last question:
Private Shared Function GetHardwareItemInfo(item As String, wmiclass As String) As String
Dim data As String = ""
Dim query As String = String.Format("Select {0} From {1}", item, wmiclass)
Using mbs As ManagementObjectSearcher = New ManagementObjectSearcher(query)
For Each mo As ManagementObject In mbs.Get
For Each pd As PropertyData In mo.Properties
' should be only one
If String.Compare(pd.Name, item, StringComparison.InvariantCultureIgnoreCase) = 0 Then
' value is object, test for Nothing
If pd.Value IsNot Nothing Then
data = pd.Value.ToString
End If
Exit For
End If
Next
Next
End Using
Return data
End Function
This allows you to poll for different items in different wmi classes using the same code. Example:
' get the serialnumber item from the baseboard class:
answer = GetHardwareItemInfo("serialNumber", "Win32_BaseBoard")
For a hardware signature:
Get and store the info for each item
Combine them into one string
Convert the string to a byte array
Use crypto to hash the byte array
convert the result to a base64 string
There are other ways. For instance you could encode the result as a Hex string, but the above is what the code shows. First, these are the namespaces you need:
Imports System.Security.Cryptography
Imports System.Management
Imports System.Text
Then the procedure to get the stuff using the GetHardwareItemInfo method above:
' place to store bits of data
Dim HWStuff As New List(Of String)
Dim answer As String
' get and store some info
answer = GetHardwareItemInfo("serialNumber", "Win32_BaseBoard")
HWStuff.Add(answer)
answer = GetHardwareItemInfo("uuid", "win32_ComputerSystemProduct")
HWStuff.Add(answer)
answer = GetHardwareItemInfo("serialNumber", "Win32_OperatingSystem")
HWStuff.Add(answer)
'...etc
' glue the bits together into one string
Dim HWSig = String.Join("", HWStuff)
Dim byteHash As Byte()
' create crypto hasher
Using hasher = New SHA1Managed()
' convert the string to bytes
Dim tmpBytes = Encoding.UTF8.GetBytes(HWSig)
'hash the bytes
byteHash = hasher.ComputeHash(tmpBytes)
End Using
' encode as B64 string.
Dim HWHash = Convert.ToBase64String(byteHash)
Console.WriteLine(HWHash)
Result:
MUjeLeZtbTQ3Rc8zgFquBkOwFzA=
You could glue the string together as you get answers. But during development it helps to see the candidate info before you decide to use it or not.
Notes:
There are many many things to choose from. See WMI Win32 Classes.
Not everything needs to come from WMI. the LocalMachine name might be a good one (I have no idea of the context for this) as is the Windows Activation Key.
Other crypto hashers will produce longer hashes
This is far from foolproof.
Some things can be spoofed - the Win OS Serial number can be changed in the registry. You dont really care if the values are right, just that they do not change.
This is not copy protection. Someone could sniff out the token(s) sent from a legitimate system(s), then patch your app to send that token only.
if I store a special id...
No. Do not write anything down. Its impossible to keep a secret from the user on their own PC. Dont store the hash either - generate it every time. If you write it down it is easier to copy that value to a different machine.
I give fake ban, the users will be angry for me...
Since it sounds like you are working from a blacklist rather than a whitelist, you dont have to worry about the hash failing. The worst that will happen is that a system which should be denied access will get access. If you want to further reduce the chance of a match, use SHA512Managed; it will produce a longer hash though.
If a user changes one of the parts you are polling, they will still get in - it is quite unlikely that the hash from 2 systems will match (one white, one black).

Properly Handling Large Amounts of Data

I've ventured into extremely unknown territory and I need some advice. I'm building an IRC bot for Twitch that could potentially contain hundreds of thousands of accounts. Previously I used Dictionary(of String, Integer) to store these accounts and their balance in memory, and just wrote them to a text file and saved it to disk. Now I'm storing a lot more data like their online time, whether they are a follower, or subscriber, how much they've donated. So I've started utilizing SQLite to store the accounts and I believe I need to utilize DataGridView with virtualmode to display these accounts and allow the user to edit any data. Am I on the right track so far? My aim is to keep it simple while managing larges amount of data, hopefully that wasn't an oxymoron.
Now I imagine the accounts in the SQLite database will need to be cached so that it's not constantly reading the database from the hard drive when a change needs to be made or when the user is scrolling through his list of accounts in the datagridview(which is in virtualmode). Am I right so far?
If there is another, more simpler method I could utilize please let me know, otherwise can someone help comprehend how I could cache these accounts? I did consider writing them to a Dictionary(of String, String) and then splitting the string when I needed to work with a specific value. Anyways I await your suggestions or comments.
Thank you.
As per my comment above, you need to look into classes. See below for little example...
Public Class Accounts
Public Property AccountID As Integer = 0
Public Property AccountName As String = String.Empty
Public Property IsFollower As Boolean = False
**'Add more properties as needed'**
Public Sub New()
End Sub
End Class
Next you can do a call to your database and get all the id's from the table; you can use these to query the rest of your data for a specific id...
Loop through your id's that you have and get their data...
Dim nAccount As Account = Nothing
For each blah blah blah....
nAccount = query from database... which will return your Account class object...
Now you can add this object (your account class) to a collection; for example a Dictionary(Of Integer, Account) Or ListOf()
As I have mentioned before there are a few different ways to go about this, it just depends on what you need to do and how you want to handle the data.

Lotus Notes and VBA Checking Email Address in Public Address Books

I'm trying to figure out how to check whether an e-mail address is in the public address book by using VBA. I found some code on the Web, modified it but the code gives an error 91 at line, "Set doc = view.GetAllDocumentsByKey(ChkEmailAddr)." I think that the problem has to do with the declaration type of the variable "view" or the type of view in the line "Set view = b.GetView("People\By Internet Mail")."
I'm pretty certain that I have all of the proper references activated. "Lotus Notes Domino Objects" and "Lotus Notes Automation Classes" are chosen.
I tried to get a list of views but I couldn't figure out how to do it. Do you see the error in my code or have ideas as to what I could try to do some troubleshooting?
Sub CheckEmailAddress()
Dim books As Variant
Dim view As lotus.NotesView
'Dim view As Object
Dim doc As NotesDocumentCollection
Dim dc As NotesDocument
Dim done As Variant
Dim docarr(3, 50) As Variant
Dim ChkEmailAddr As String
ChkEmailAddr = "user#example.com"
Set Session = CreateObject("Notes.Notessession")
books = Session.AddressBooks
done = False
For Each b In books
' check every public address book,
' unless we're already done
If (b.IsPublicAddressBook) Then
Debug.Print TypeName(b)
Call b.Open("", "")
Debug.Print b.Title
' look up person's last name
' in People view of address book
Set view = b.GetView("People\By Internet Mail")
Debug.Print TypeName(view)
'Debug.Print view
'Set view = b.GetView("main")
'Debug.Print TypeName(view)
Set doc = view.GetAllDocumentsByKey(ChkEmailAddr)
' if person is found, display the phone number item
'from the Person document
If Not (doc Is Nothing) Then
For j = 0 To doc.Count
docarr(0, j) = doc.GetNthDocument(j).Items(11).Text
docarr(1, j) = doc.GetNthDocument(j).Items(93).Text
docarr(2, j) = doc.GetNthDocument(j).Items(95).Text
docarr(3, j) = doc.GetNthDocument(j).Items(14).Text
Next j
End If
End If
Next b
findEmailLotus = docarr
End Sub
I'm sorry to say this, but you have a lot of issues here. Whoever wrote that code that you started from did not know what he or she was doing.
First of all, unless you are requiring that the Notes client is running while your code is running, you should be using Lotus.NotesSession instead of Notes.NotesSession. (The former corresponds to the "Lotus Notes Domino Objects", and uses COM to talk to the Notes APIs, and the latter corresponds to the "Lotus Notes Automation Classes, and uses OLE to talk to the Notes client to talk to the APIs - hence the requirement that the client must be running.)
Secondly, you haven't mentioned what version of Lotus Notes you are dealing with, but more recent versions (8 and above) include the NotesDirectory class, which includes a LoookupNames method that would probably be a better solution for you than writing your own code to loop through address books.
Third, after doing your set view operation, you really ought to be doing an If Not view is Nothing test. That will tell you whether or not you actually have a problem opening the view.
Fourth, doc is a really bad variable name for the return value from GetAllDocumentsByKey. In 20+ years of writing Notes code, I can say that anybody reading Notes code expects the variable name doc to always refer to a single document. You are getting a NotesDocumentCollection, not a single document. Do yourself a favor and change it to docs or dc, or just about anything except doc.
Fifth, using GetNthDocument in this context is usually not recommended. It performs very badly in large collections. Even worse, however, is that you are calling it four times when you could be making only one call per iteration. Instead of a For loop, consider changing it to a call to GetFirstDocument followed by While Not doc is Nothing loop that retrieves your item values and stores them in your array, and then calls getNextDocument at the bottom of the loop.
Sixth, that code referencing .Items(11), .Items(93)... that's just plain wrong. The available items within any given document are variable because Notes is schemaless. Those item numbers will refer to different fields for different people - i.e., essentially random values. That can't possibly be what you want. You should be using getFirstItem() calls with the actual names of the items that you really want to be putting in your array. You will need to study the field names used in the Domino Directory to figure this out. I recommend NotesPeek as a good tool for exploring Notes databases and/or just opening up the Domino Directory in the Domino Designer client and looking at the Person form (and associated subforms) to figure out what you need.
As to the actual error you asked about, my guess is that by adding the recommended test of If Not view Is Nothing you will gain more information, but perhaps not enough. You haven't mentioned what your debug prints are generating, but I believe there are some cases where the title is available even if the database was not successfully opened, so I don't think you should trust that as a test of whether the call worked. In fact, you really shouldn't just be doing a Call db.open("","") call. You should be doing an If db.open("","") = true to test whether it actually worked.
For people who know lotus notes, it's trival. For those that don't, there might be an easier way using web access.
Request this address
Keep your cookies
http://server/names.nsf?login&username=MYUSERNAM&password=MYPASSWORD
Then access this url and look for a 404 status or a 200 status
http://server/names.nsf/($Users)/email#domain.com?opendocument
Of course, that requires that you have web access enabled on your server and in many cases putting your password in your code is bad, and it won't work if your servers are configured in some ways.
Before coding, test it on your server.