473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Can you take specific text from a textbox and input it into a messagebox?

I have a messagebox that asks if I want to delete a specific ebook from my listbox.
The message says, "“Do you want to remove the x eBook?” the x needs to be the title of the book selected.
This is what I have:

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
  2.         ' removes the selected line from the list box
  3.         Dim x As String = lstEbooks.Text()
  4.  
  5.         If MessageBox.Show(“Do you want to remove the " & 
  6.                         x & " eBook?”,
  7.                        "eBooks", MessageBoxButtons.YesNo,
  8.                         MessageBoxIcon.Warning,
  9.  
  10.                          MessageBoxDefaultButton.Button1) 
  11.                          = DialogResult.Yes Then
  12.  
  13.             ' if a line is selected, remove the line
  14.             If lstEbooks.SelectedIndex <> -1 Then
  15.                 lstEbooks.Items.RemoveAt(lstEbooks.SelectedIndex)
  16.             End If
  17.         End If
  18.     End Sub 
Each line in the textbox has Title, Author, and Price
So, my x is showing Title, Author, and Price.

Examples:

Textbox shows:
Allegiant Veronica Roth 3.99
Divergent Veronica Roth 2.99

My message is showing:
Do you want to remove the Allegiant Veronica Roth 3.99 eBook?

What I want is: Do you want to remove the Allegiant eBook?

Please, any suggestions?

Thanks


Here is the full program:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit On
  2. Option Strict On
  3. Option Infer Off
  4. ' Name:         Ebook Project
  5. ' Purpose:      Adds and deletes list box entries
  6. '               Reads information from a sequential access file
  7. '               Writes information to a sequential access file
  8. ' Programmer:   Amanda Lovett on 04-07-17
  9.  
  10. Imports System.Reflection
  11.  
  12. Public Class frmMain
  13.  
  14.     Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
  15.         ' fills the list box with data from 
  16.         ' a sequential access file
  17.  
  18.         Dim inFile As IO.StreamReader
  19.         Dim strInfo As String
  20.  
  21.         ' verify that the file exists
  22.         If IO.File.Exists("Ebooks.txt") Then
  23.             'open the file for input
  24.  
  25.             inFile = IO.File.OpenText("Ebooks.txt")
  26.             ' process loop instructions until end of file
  27.             Do Until inFile.Peek = -1
  28.                 strInfo = inFile.ReadLine
  29.                 lstEbooks.Items.Add(strInfo)
  30.             Loop
  31.             inFile.Close()
  32.             ' select the first line in the list box
  33.             lstEbooks.SelectedIndex = 0
  34.         Else
  35.             MessageBox.Show("Can't find the Ebooks.txt file",
  36.                             "eBooks", MessageBoxButtons.OK,
  37.                             MessageBoxIcon.Information)
  38.         End If
  39.     End Sub
  40.  
  41.     Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
  42.         ' adds eBook information to the list box
  43.  
  44.         ' declare variables
  45.         Dim strTitle As String
  46.         Dim strAuthor As String
  47.         Dim strPrice As String
  48.         Dim strConcatenatedInfo As String
  49.         Dim dblPrice As Double
  50.  
  51.         ' get the eBook information
  52.         strTitle = InputBox("Title:", "eBooks")
  53.         strAuthor = InputBox("Author:", "eBooks")
  54.         strPrice = InputBox("Price", "eBooks")
  55.  
  56.         ' format the price, then concatenate the input
  57.         ' items, using 40 characters for the title, 
  58.         ' 35 characters for the author, and 5 
  59.         ' characters for the price
  60.         Double.TryParse(strPrice, dblPrice)
  61.         strPrice = dblPrice.ToString("n2")
  62.         strConcatenatedInfo = strTitle.PadRight(40) &
  63.             strAuthor.PadRight(35) & strPrice.PadLeft(5)
  64.  
  65.         ' add the information to the list box
  66.         lstEbooks.Items.Add(strConcatenatedInfo)
  67.     End Sub
  68.  
  69.     Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
  70.         ' removes the selected line from the list box
  71.         Dim x As String = lstEbooks.Text()
  72.  
  73.         If MessageBox.Show(“Do you want to remove the " & x & " eBook?”,
  74.                         "eBooks", MessageBoxButtons.YesNo,
  75.                         MessageBoxIcon.Warning,
  76.                            MessageBoxDefaultButton.Button1) = DialogResult.Yes Then
  77.             ' if a line is selected, remove the line
  78.             If lstEbooks.SelectedIndex <> -1 Then
  79.                 lstEbooks.Items.RemoveAt(lstEbooks.SelectedIndex)
  80.             End If
  81.         End If
  82.     End Sub
  83.  
  84.     Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
  85.         ' save the list box information
  86.  
  87.         ' declare a StreamWriter variable
  88.         Dim outFile As IO.StreamWriter
  89.  
  90.         ' open the file for output
  91.         outFile = IO.File.CreateText("Ebooks.txt")
  92.  
  93.         ' write each line in the list box
  94.         For intIndex As Integer = 0 To lstEbooks.Items.Count - 1
  95.             outFile.WriteLine(lstEbooks.Items(intIndex))
  96.         Next intIndex
  97.  
  98.         ' close the file
  99.         outFile.Close()
  100.  
  101.     End Sub
  102.  
  103.     Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
  104.         Me.Close()
  105.     End Sub
  106. End Class   
Apr 9 '17 #1
1 1228
Luk3r
300 256MB
I think you could benefit from doing something similar to this, assuming your textbox items always have the same format, where the word you want to display is followed by a space:

Expand|Select|Wrap|Line Numbers
  1. Dim x As String = lstEbooks.Text.SubString(0, lstEbooks.Text.IndexOf(" "))
Apr 10 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Massy | last post by:
Does anyone know how can ensure that the only input that is accepted into a textbox is a numeric (only digits 1-9 accepted) Is this possible I am using vb.net to create a windows app thx...
0
by: ramnaresh_t yadav via .NET 247 | last post by:
Hi, I am pasting the code to import data from Text/Excel files into Database(Oracle ) Table... I think some one needs this .. they can use.. it... ======================= Dim dsDB As New DataSet...
2
by: Matt | last post by:
Hi, I'm ridiculously new to Access (about a week!) so please be patient! My database is a record of British Standards. Each has a unique identifier. Some are split into parts. I would like...
6
by: Rancid Buttchutney | last post by:
I guess the subject says it all, really, and I know it's not a standard of the feature-set, but has anyone experimented with it? I'm writing an autocompleting INPUT element and would like it to...
13
by: so many sites so little time | last post by:
say i want spacing in my text so instead of doing <br> <br> in between the lines or having to do <href = or <a href = for a link what could i do to have php enter to mysql or retrive it formated?
1
by: Don Croner | last post by:
I am using access 2003 with windows xp. I have created a data base for to keep track of my 180 employees. I have created a table with 21 records. Then I created a form to input employee data. I...
1
by: sandhyamn | last post by:
hi...i am trying to write a programme for uploading file with jsp using multipart/form data.it's working.....but the problem is i can't write the textbox values into a file....if change the form...
2
by: Dave Almighty | last post by:
I've spent the last couple of hours looking desperately through every corner of the internet for a solution to the following question (and my teeth have been ground down almost to nothing). With a...
2
by: dpw.asdf | last post by:
I have been searching all over for a solution to this. I am new to Python, so I'm a little lost. Any pointers would be a great help. I have a couple hundred emails that contain data I would like to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.