Back button in a vb.net program - vb.net

I am trying to write the code for a back button in my VB.NET app. But it is not working. What is wrong with it?
Private Sub BackBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackBtn.Click
Dim returntext As String = Clipboard.GetText()
lblDictword.Text = returntext
Dim returnHtmlText As String = Nothing
If (Clipboard.ContainsText(TextDataFormat.UnicodeText)) Then
returnHtmlText = Clipboard.GetText(TextDataFormat.UnicodeText)
'Clipboard.SetText(replacementHtmlText, TextDataFormat.Html)
Clipboard.SetText(returnHtmlText, TextDataFormat.UnicodeText)
End If
lblDictword.Text = returnHtmlText
'Return returnHtmlText
Dim count As Integer = myStrings.Length
If count > 1 Then
Dim s As String = myStrings.ElementAt(count - xd)
xd = Array.IndexOf(myStrings, s)
lblDictword.Text = s
End If
End Sub

I am not an VB.NET expert, but usually getting access to clipboard isn't as easy as it looks. Check this:
Problem with clipboard class
It can be only a tip, not really solution. Look into your clipboard functionallity

Related

I am trying to use clipboard object in class project of vb.net but I can't seem to be able to use it

I am trying to get clipboard text in vb.net class project but the clipboard object is not working
Dim clipText As String = String.Empty
If Clipboard.ContainsText Then
clipText = Clipboard.GetText()
End If
I am using this code but its giving me error
Dim clipboardText As String = System.Windows.Forms.Clipboard.GetText()
I am trying to use this but system. Windows doesn't have .forms but it has .input and .others what am I missing I tried referencing it from the references but it doesn't seem to work either
This is from a little project where i load code from a SQLite DB into a RichTextBox then click a button to copy that code to the clip board.
Private Sub btnCopySelCode_Click(sender As Object, e As EventArgs) Handles btnCopySelCode.Click
CopySelected()
End Sub
Public Sub CopySelected()
Dim start = rtbViewCode.SelectionStart
Dim substring = rtbViewCode.Text.Substring(0, start)
Dim words = substring.Split(New String() {" ", vbCrLf}, StringSplitOptions.None)
Dim gvW = rtbViewCode.SelectedText
Dim count = gvW.Length
If count <= 0 Then
gvalertType = "14"
frmAlert.ShowDialog()
rtbViewCode.Focus()
Return
End If
Clipboard.SetText(gvW)
ansQ()
End Sub

Getting strings from a textfile in a combobox, vb.net

Here is my code :
I'm trying to have some value out from a TXT file to a combobox or label but i feel combobox would be easier.
here's my code :
please note, some config.txt will only have 1 value while other 5-6
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IDinFile As String
Dim ID As String
If IO.File.Exists("config.txt") Then
Using StreamReader As New IO.StreamReader("config.txt")
Do
IDinFile = StreamReader.ReadLine
If (IDinFile.IndexOf("7656")) <> -1 Then
ID = IDinFile.Substring(2)
ID = ID.Trim().Remove(ID.Length - 1)
ComboBox1.Items.Add(ID)
Exit Do
End If
Loop Until IDinFile Is Nothing
End Using
End If
End Sub
the file here in .png :
https://i.stack.imgur.com/iYaqP.png
Re-written the code for you. Problem was wrongly placed Exit Do. Also, its advisable to check the line before entering the loop rather than at the end of the loop.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IDinFile As String
Dim ID As String
Const FILENAME As String = "config.txt"
If IO.File.Exists(FILENAME) Then
Using StreamReader As New IO.StreamReader(FILENAME)
Do While StreamReader.Peek() >= 0
IDinFile = StreamReader.ReadLine.Trim()
If (IDinFile.IndexOf("7656")) <> -1 Then
ID = IDinFile.Substring(1, IDinFile.Length - 2)
ComboBox1.Items.Add(ID)
End If
Loop
End Using
End If
End Sub
After you add the first item to the combobox you have an Exit Do statement. It no longer continues checking further lines and adding them to the combobox.
You should remove that statement.
Try this. It'll work if the values are organized line by line in the txt file.
Dim srd as New StreamReader("config.txt")
If io.file.exists("config.txt") then
Dim str() = srd.ReadToEnd.split(environment.newline)
For i = 0 to str.count-1
Combobox.item.add(str(i))
Next
srd.close

Get Source Code from Webview (VB for Metro)

I'm Making a Windows Phone's app that I can, From a webview called "DebWeb", get the ClassRoom of a specific class. The DebWeb load the site where is all the classRooms, but I want to make that my App search just my class.
Before I made an app with almost the same objetive (search the Name of a App from the Source Code), but it was made from VB for PC, now I'm working on VB for Metro (or for App Store) and I can't use the same code.
For example, On VB for PC I can use:
Dim EHTML = DebWeb.Document.All.Item(1)
Dim sourceString As String = EHTML.InnerHtml
'Use Regex Match to search from SourceString"
But on VB for Metro it's shows me the " 'Document' is not a member of 'Windows.UI.XAML.Controls.WebView' " error, so I can't get the Source Code from the page and I can't look for the ClassRoom.
I Looked on the MSDN page about Webview but the most close thing that I can do is to get the "DocumentTittle", but not the content.
This is my code, everything "works" except the "Source" variable:
Dim Source = DebWeb.[Control] 'Here is where I need the Control to get the SourceCode
Dim m As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(Source.ToString, _
"DERECHO CONSTITUCIONAL", _
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Edited with my Entire code:
Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim URL As String = "http://goo.gl/uqohKw"
Me.DebWeb.Navigate(New Uri(URL))
End Sub
Private Sub DebWeb_LoadCompleted(ByVal sender As Object, ByVal e As WebViewNavigationCompletedEventArgs)
LListo.Text = "Listo!"
Dim html As String = DebWeb.InvokeScriptAsync("eval", New String() {"document.documentElement.outerHTML;"}).ToString
Dim Source = html
Dim m As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(Source.ToString, _
"LECTURA CRÍTICA", _
System.Text.RegularExpressions.RegexOptions.IgnoreCase)
If (m.Success) Then
Dim key As String = m.Groups(1).Value
End If
End Sub
Something like this?
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Try
Dim html As String = Await myWebView.InvokeScriptAsync("eval", New String() {"document.documentElement.outerHTML;"})
Catch ex As Exception
End Try
End Sub
More Info here

HI, New to programming with textfiles loops and much more

i have a textfile which is in this format
and i am trying to use a stream reader to help me loop each word into a text box, i am new to programming and really need help because all other examples are too complicated for me to understand,
this is what i am trying to do :
Dim objectreader As New StreamReader("filepath")
Dim linereader(1) As String
linereader = Split(objectreader.ReadLine, ",")
For i As Integer = 0 To UBound(linereader)
Spelling_Test.txtSpelling1.Text = linereader(0)
Spelling_Test.txtSpelling2.Text = linereader(0)
Next
but only get the first line of the text file in to a textbox, i need it to loop to the next line so i can write the next line in!
your help would be much appreciated, and if possible then can you show it practically , if you dont understand what i am trying to do then please ask
It is a little confusing on what you are trying to do, it looks like your text file consists of a word and a hint, you only have one set of textbox's and 3 lines of information in your file.
This example show you how to incrementally read your Stream.
Public Class Form1
Dim objectreader As StreamReader
Dim linereader() As String
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If IsNothing(objectreader) Then
objectreader = New StreamReader("C:\Temp\data.txt")
End If
linereader = Split(objectreader.ReadLine, ",")
If String.IsNullOrEmpty(linereader(0)) Then
objectreader.Close()
objectreader = Nothing
Else
txtSpelling1.Text = linereader(0) 'Word
txtSpelling2.Text = linereader(1) 'Hint
End If
End Sub
End Class
But in your case, I would probably just use the File.ReadAllLines Method
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim result As String() = File.ReadAllLines("C:\Temp\data.txt")
For x = 0 To UBound(result)
Dim c As Control = Controls.Find("txtSpelling" + (x + 1).ToString, True)(0)
If Not IsNothing(c) Then
c.Text = Split(result(x), ",")(0)
End If
Next
End Sub

WP7 - Updating a listbox

I've finally got around to starting windows phone dev. I'm not very good at it yet, but anyway, I hope you guys understand what I want to do here.
From what I've learnt from other programmers, an ObservableCollection can be updated in live time whilst it is databound to an object, such as a listbox. All changes to the ObservableCollection will cause the UI of the object it's databound to update it's items.
So what I'm trying to do, is download a file from my server, parse it with json, then update the ObservableCollection with the new data. However, the webclient doesn't seem to be downloading the new data until the app is re opened!
Here's a gif showing how the app works at the moment:
And here's my code (cut down a bit):
Dim aList As New ObservableCollection(Of classes.consoles)
Private Sub PhoneApplicationPage_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
checkforconsoles()
End Sub
Public Sub checkforconsoles()
Dim wc As New WebClient()
AddHandler wc.DownloadStringCompleted, AddressOf downloaded
wc.DownloadStringAsync(New Uri("http://localhost/api/?function=GetConsolesForUser&userid=" & id))
End Sub
Private Sub downloaded(sender As Object, e As DownloadStringCompletedEventArgs)
aList.Clear()
'MessageBox.Show(e.Result)
Dim o As JObject = JObject.Parse(e.Result)
Dim jarray As JArray = DirectCast(o("results"), JArray)
Try
Dim i As Integer = jarray.Count()
For i = 0 To jarray.Count() - 1 Step 1
Dim id As String = jarray(i)("id").ToString
Dim name As String = jarray(i)("name").ToString
Dim image As String = jarray(i)("image").ToString
MessageBox.Show(name)
Dim c As classes.consoles = New classes.consoles()
c.categoryimage = New Uri(image)
c.categoryname = name
c.categoryid = id
aList.Add(c)
Next
listBoxview.ItemsSource = aList
StackPanel1.Visibility = Windows.Visibility.Collapsed
StackPanel2.Visibility = Windows.Visibility.Visible
Catch ex As Exception
StackPanel2.Visibility = Windows.Visibility.Collapsed
StackPanel1.Visibility = Windows.Visibility.Visible
End Try
End Sub
Private Sub ApplicationBarIconButton_Click_1(sender As System.Object, e As System.EventArgs)
checkforconsoles()
End Sub
Does anybody have any clue what's wrong? :(
Thanks in advance.
It's a cachine issue with the WebClient. You can append a random query string to ensure that the URL is always unique so that the WebClient doesn't cache the results. One way to do this is to add a random GUID value since it's very unlikely to generate two of the same GUIDs in a short time frame.
wc.DownloadStringAsync(New Uri("http://localhost/api/?function=GetConsolesForUser&
userid=" & id & "&random=" + Guid.NewGuid().ToString()))