Ignore this to get to the main problem, below is only the idea
Scenario: I am making a total Private Messaging system in Visual Basic.
Trying: I want to make an Inbox for the users. The messages will be retrieved from the MySQL database and shown in small custom Grid made with Panel(Type of Control from Visual basic) for each message which will be clickable which is when clicked, the whole message will be shown.
Did so far: Not too much though(Talking about the Inbox.), I only wrote the MySQL query.
I will make the Sending and Reading PM after the Inbox as Inbox seems more complex than the other two things.
I really want to know how can this be achieved. I searched around almost everywhere, either it was for PHP and web based or nothing. I want to know how to dynamically create controls like panels and the labels and show the PMs. Is there any other way to do this rather than showing the PMs in DataGridView ? (I really don't want to use that as it's not what I want.)
For reference: The custom Grid is something like this:
The MySQL PM table:
PMId - The ID for the message (Auto Incremented)
Sender_Name - The person sending the message
Receiver_Name - The person receiving the message
Subject - The subject of the message
Date_Sent - Date on which the message was sent
PM_Read - If the PM has been read (0 for not read, 1 for read)
Deleted - If the PM has been deleted (0 for not deleted, 1 for deleted)
Look at the code-behind for a built form and you will see how to create controls at run-time. For example, I created a form, added a panel with a button and label and this is the code created in the designer:
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(3, 3)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(3, 29)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
'
'Panel1
'
Me.Panel1.Controls.Add(Me.Button1)
Me.Panel1.Controls.Add(Me.Label1)
Me.Panel1.Location = New System.Drawing.Point(12, 12)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(198, 69)
Me.Panel1.TabIndex = 2
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.Panel1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.Panel1.ResumeLayout(False)
Me.Panel1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Panel1 As System.Windows.Forms.Panel
You can do the same thing at run-time.
Dim iTop As Int32 = 5
For Each DR As DataRow In DT.Rows
Dim pnl As New Panel
pnl.Location = New System.Drawing.Point(12, iTop)
pnl.Size = New System.Drawing.Size(198, 40)
Dim lbl As New Label
lbl.Location = New System.Drawing.Point(3, 3)
lbl.Size = New System.Drawing.Size(39, 13)
lbl.Text = DR("Some field from your table")
'Add to panel
pnl.Controls.Add(lbl)
'Add to Form
Me.Controls.Add(pnl)
'Add to the top location so the next set of controls are not on top of the old ones
iTop += 50
Next
Related
I'm having the following problem which is once I populate some inputbox on IE with information from Excel using VBA, these are populated correctly but when i change onto the second line with input boxes (they all are the same in format) the one I filled before does not get saved (even if I press save).. the only way I found for the information to remain is if I get into any of these boxes I'm filling and type something manually.
Anyone has an idea of why this might be?
Thanks!
For Each cell In wsbd.range(range("A6"), range("A6").End(xlDown))
additemsbtn.Click
Set aNodeList = ieDoc.querySelectorAll("[dojoinsertionindex]")
aNodeList.Item(0).Click
For i = 0 To 15
If ieDoc.getElementById("meetingResultsPlanningTable").getElementsByTagName("select")(0).Item(i).innerText = wsbd.range("A6").Value Then
ieDoc.getElementById("meetingResultsPlanningTable").getElementsByTagName("select")(0).Item(i).Selected = True
Exit For
End If
Next i
Set dropOptions = ieDoc.getElementById("meetingResultsPlanningTable").getElementsByTagName("select")(5)
dropOptions.Value = "Value"
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("InputBox")(0)
itemName.Value = wsbd.range("F6").Value
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox2")(0)
itemName.Value = wsbd.range("J6").Value
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox")(0)
itemName.Value = wsbd.range("Q6").Value
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox")(1)
itemName.Value = wsbd.range("T6").Value * 100
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox")(1)
itemName.Value = itemName.Value + 0
'Set savebtn = ieDoc.getElementById("/images/buttons/save.gif")
' savebtn.Click
Next cell
The code is working and is reading properly all the inofrmation in Excel, finding the corresponding Input boxes and populating them but then nothing gets saved or recorded.. as you can see I tried saving after completing the boxes but it still doesn't work...
I came up with a solution! And pretty simple by the way.. I just added a fireevent ("onchange") for each input box and that records all changes!
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("InputBox")(0)
itemName.Focus
itemName.FireEvent ("onchange")
itemName.Value = somevalue.Value
I'm Having a problem regarding to the autocomplete textbox. First I already made the autocomplete textbox work with mysql database as custom source but the default textfilter of autocomplete is "start with" not "contains". I want to change the textfilter to "contains", so that when I search any part of the string, the whole name which contains the searched word will appear in the autocomplete suggestions.
Can anyone help me fix my code?
This is the code i've done so far:
txtSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend
txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim DataCollection As New AutoCompleteStringCollection()
Dim query As String
sqlcon = New MySqlConnection
sqlcon.ConnectionString =
"server=localhost;userid=root;password=root;database=svfmemberlistdb"
Try
sqlcon.Open()
query = " SELECT Name FROM svfmemberlistdb.svfmemberlist "
sqlcmd = New MySqlCommand(query, sqlcon)
sqladr.SelectCommand = sqlcmd
sqladr.Fill(ds)
sqladr.Dispose()
sqlcon.Close()
For Each row As DataRow In ds.Tables(0).Rows
If row.ToString.Contains(txtSearch.Text) Then
DataCollection.Add(row(0).ToString())
End If
Next
Catch ex As Exception
End Try
txtSearch.AutoCompleteCustomSource = DataCollection
I quote here Mitja Bonca's answer on MSDN.
In this case, autocompletemode will just not do. Its code is not meant
for something like it.
You will have to do your own code, to do the filtering on each letter
press.
So I would suggest not to use autocompletemode, and get all the data
(names) into dataTable. When user presses some button ("1" for
example), you start with your filtering, by creating new Datatable
(leave the main one untached - so you can return back to all data when
clearing comboBox by backspace), with Copy() method - to create a full
copy of original one, and use Select method to do the filteing.
This should look something like by using % simbol on both sides of a
string - to filter inbetween - this is what you want!
DataTable AllNames = new DataTable();
//fill it up and leave it untouched!
//to filter comboBox with names that contains pressed characters do in
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string name = string.Format("{0}{1}", comboBox1.Text, e.KeyChar.ToString()); //join previous text and new pressed char
DataRow[] rows = table.Select(string.Format("FieldName LIKE '%{0}%'", name));
DataTable filteredTable = AllNames.Clone();
foreach(DataRow r in rows)
filteredTable.ImportRow(r);
comboBox1.DataSource = null;
comboBox1.DataSource = filteredTable.DefaultView;
comboBox1.DisplayMember = "FieldName";
}
Reference
EDIT: This is of course a c# answer not VB.NET but it might be helpful to get the concept.
I have a problem in this line of code:
myCommands = New OdbcCommand("select * from customer where uname='" + Session("user") + "'", myConnections)
my goal here is to display all the user's information in a page tab, but it only shows a blank page.
Posting my comment as an answer:
myCommands = New OdbcCommand("select * from customer where lower(uname) = lower(#user)"), myConnections);
myCommands.Parameters.Add("#user", OdbcDbType.NVarChar).Value = Session["user"].ToString();
This solved a problem.
I'm new to LibreOffice Basic. I'm trying to write a macro in LibreOffice Calc that will read the name of a noble House of Westeros from a cell (e.g. Stark), and output the Words of that House by looking it up on the relevant page on A Wiki of Ice and Fire. It should work like this:
Here is the pseudocode:
Read HouseName from column A
Open HtmlFile at "http://www.awoiaf.westeros.org/index.php/House_" & HouseName
Iterate through HtmlFile to find line which begins "<table class="infobox infobox-body"" // Finds the info box for the page.
Read Each Row in the table until Row begins Words
Read the contents of the next <td> tag, and return this as a string.
My problem is with the second line, I don't know how to read a HTML file. How should I do this in LibreOffice Basic?
There are two mainly issues with this.
1. Performance
Your UDF will need get the HTTP resource in every cell, in which it is stored.
2. HTML
Unfortunately there is no HTML parser in OpenOffice or LibreOffice. There is only a XML parser. Thats why we cannot parse HTML directly with the UDF.
This will work, but slow and not very universal:
Public Function FETCHHOUSE(sHouse as String) as String
sURL = "http://awoiaf.westeros.org/index.php/House_" & sHouse
oSimpleFileAccess = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
oInpDataStream = createUNOService ("com.sun.star.io.TextInputStream")
on error goto falseHouseName
oInpDataStream.setInputStream(oSimpleFileAccess.openFileRead(sUrl))
on error goto 0
dim delimiters() as long
sContent = oInpDataStream.readString(delimiters(), false)
lStartPos = instr(1, sContent, "<table class=" & chr(34) & "infobox infobox-body" )
if lStartPos = 0 then
FETCHHOUSE = "no infobox on page"
exit function
end if
lEndPos = instr(lStartPos, sContent, "</table>")
sTable = mid(sContent, lStartPos, lEndPos-lStartPos + 8)
lStartPos = instr(1, sTable, "Words" )
if lStartPos = 0 then
FETCHHOUSE = "no Words on page"
exit function
end if
lEndPos = instr(lStartPos, sTable, "</tr>")
sRow = mid(sTable, lStartPos, lEndPos-lStartPos + 5)
oTextSearch = CreateUnoService("com.sun.star.util.TextSearch")
oOptions = CreateUnoStruct("com.sun.star.util.SearchOptions")
oOptions.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
oOptions.searchString = "<td[^<]*>"
oTextSearch.setOptions(oOptions)
oFound = oTextSearch.searchForward(sRow, 0, Len(sRow))
If oFound.subRegExpressions = 0 then
FETCHHOUSE = "Words header but no Words content on page"
exit function
end if
lStartPos = oFound.endOffset(0) + 1
lEndPos = instr(lStartPos, sRow, "</td>")
sWords = mid(sRow, lStartPos, lEndPos-lStartPos)
FETCHHOUSE = sWords
exit function
falseHouseName:
FETCHHOUSE = "House name does not exist"
End Function
The better way would be, if you could get the needed informations from a Web API that would offered from the Wiki. You know the people behind the Wiki? If so, then you could place this there as a suggestion.
Greetings
Axel
I am using C# and outlook-addin.
I want to be able to have the user select a part of the mail message/body and I want to be able to copy the selected items, and it store it to an sql server database.
Outlook.Application myApplication = Globals.ThisAddIn.Application;
Outlook.Explorer myActiveExplorer =
(Outlook.Explorer)myApplication.ActiveExplorer();
Outlook.Selection selection = myActiveExplorer.Selection;
if (selection.Count == 1 && selection[1] is Outlook.MailItem)
{
Outlook.MailItem mail = (Outlook.MailItem)selection[1];
mail.Copy(); // currently opened mail
Outlook.MailItem mailItem = (Outlook.MailItem)
myApplication.CreateItem(
Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.Subject = mail.Subject;
mailItem.To = mail.To;
mailItem.Body = ????? // copy only selected text/images of user
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
mailItem.Display(true);
}
On the mailITem.Body, I just want to paste the selected text/images of the user from the selected mail (the currently opened email).
I cant find the paste method, How can I implement it?
Outlook cannot get the selected text in the mail body, so convert the outlook to word editor, so you can follow these 3 steps:
1. get the mail total body
2. use the word editor based on the **microsoft.office.Interop.word** dll
3. select the text and to store the any string
first add the dll reference
object oItem;
Outlook.Application oApp=new Outlook.Application();
Outlook.Explorer oExp=oApp.ActiveExplorer();
Outlook.Selection oSel= oExp.Selection;
for (i = 1; i <= oSel.Count; i++)
{
oItem = oSel[i];
Outlook.MailItem oMail = (Outlook.MailItem)oItem;
Outlook.Inspector inspector = oMail.GetInspector;
// Obtain the Word.Document object from the Inspector object
Microsoft.Office.Interop.Word.Document document =
(Microsoft.Office.Interop.Word.Document)inspector.WordEditor;
mailItem.Body = document.Application.Selection.Text;
}